matcha.explainability.lime

Attributes

logger

Classes

LIME

Local Interpretable Model-agnostic Explanations for molecular predictions.

Module Contents

matcha.explainability.lime.logger
class matcha.explainability.lime.LIME(descriptor_set: list[str] | None = None, fingerprint_params: dict | None = None, scale_coeff: bool = True, use_fingerprints: bool = False)[source]

Local Interpretable Model-agnostic Explanations for molecular predictions.

Fits bootstrapped Ridge regression models on molecular descriptors or ECFP fingerprints to identify which features most influence a prediction. Coefficients are optionally scaled to sum to 1 for interpretability.

property descriptor_set: str

The list of RDKit descriptor names used as features.

property scale_coeff: bool

Whether coefficients are scaled to sum to 1.

property r2_box: list[float]

R-squared values from each bootstrap iteration.

get_envs_and_weights(mol: rdkit.Chem.rdchem.Mol, out: pandas.DataFrame)[source]

Extracts atomic environments and weights for a molecule given a lime analysis result

Parameters:
  • mol (Mol) – rdkit molecule

  • out (pd.DataFrame) – lime analysis result

explain(X: list[rdkit.Chem.rdchem.Mol], Y: numpy.ndarray, bootstrap_num: int = 25) pandas.DataFrame[source]

Perform LIME analysis on molecules.

Fits bootstrapped Ridge regression models to explain how molecular descriptors (or fingerprint bits) relate to the target values. Returns a DataFrame of coefficients sorted by importance.

Parameters:
  • X (list[Mol]) – RDKit molecule objects to explain.

  • Y (np.ndarray) – Target values (predictions or any endpoint), shape (n_molecules,).

  • bootstrap_num (int) – Number of bootstrap iterations. Defaults to 25.

Returns:

DataFrame with columns Descriptor, Coefficient, and Standard deviation, sorted by coefficient magnitude. The last row contains the local fit R-squared summary.