liveBook · Manning

Model-agnostic method

As explained in Build AI Drug Discovery Pipelines

Model-agnostic interpretability comprises methods that explain or analyze a model's predictions without relying on its internal implementation or architecture.

A model-agnostic interpretability method analyzes predictions without relying on a model’s internal architecture. Such methods can compare feature importance across different models, including complex models used to predict whether small molecules bind to RNA. section 6.4.3 section 6.0

A molecular descriptor is a feature used to represent a molecule. Sensitivity analysis asks how changing a descriptor changes a prediction. One approach modifies a test set, predicts with both the original and modified data, and measures the difference. Descriptors can be permuted or masked to assess sensitivity across the data. section 6.4.3

Local sensitivity for an RNA binder

For one molecule, change a descriptor slightly in both directions and predict each time. The difference between the predictions, divided by twice the change, approximates a partial derivative: a local measure of how the prediction responds to that descriptor. section 6.4.3

Listing 6.9 Partial Derivative Analysis
def partial_derivative(model, X, feature_idx):
    delta = 5e-2
    X_plus = X.copy()
    X_plus[:, feature_idx] += delta
    y_pred_plus = model.predict_proba(X_plus)[:, 1]
    X_minus = X.copy()
    X_minus[:, feature_idx] -= delta
    y_pred_minus = model.predict_proba(X_minus)[:, 1]
    partial_derivative = (y_pred_plus - y_pred_minus) / (2 * delta)
    return partial_derivative
 
partial_derivatives = np.zeros(X_all_2.shape[1])
for i in range(X_all_2.shape[1]):
    partial_derivatives[i] = partial_derivative(
        best_model, X_all_2[:1], i)[0]
feature_names = df_all_2.drop(
    columns=['Library']
).columns[partial_derivatives > 1e-2]
partial_derivatives = partial_derivatives[partial_derivatives > 1e-2]
 
plt.bar(
    range(len(partial_derivatives)),
    partial_derivatives,
    tick_label=feature_names
)

The Python listing applies this central-difference calculation to each descriptor and plots derivatives greater than 0.01 for the first RNA binder. section 6.4.3

SHAP offers another approach: it uses a transparent surrogate to attribute a prediction to features. Its Shapley-value explanation considers a descriptor’s marginal contribution by comparing a group of descriptors with and without it. SHAP visualizations can summarize importance across compounds or explain a single prediction. section 6.5 section 6.4.3

Listing 6.10 SHAP Usage & Visualization
model = XGBClassifier().fit(X_all_2, y_all_2)
explainer = shap.TreeExplainer(model)    #A
shap_values = explainer.shap_values(   #B
    X_all_2[:5000]    #B
)    #B
 
shap_values_exp = shap.Explanation(
    values=shap_values, 
    base_values=explainer.expected_value, 
    data=X_all_2[:5000],
    feature_names=df_all_2.drop(columns=['Library']).columns
)
binder_type = df_all_2['Library'].tolist()[:5000]
 
shap.summary_plot(shap_values, X_all_2[:5000])
shap.plots.bar(shap_values_exp.cohorts(binder_type).abs.mean(0))
shap.plots.scatter(
    shap_values_exp[:, shap_values_exp.abs.mean(0).argsort[-1]],
    color=shap_values_exp
)
shap.plots.waterfall(shap_values_exp[1], max_display=10)

This example fits an XGBoost classifier and uses SHAP’s TreeExplainer to produce global, cohort, and individual-prediction visualizations. TreeExplainer is specific to the tree model used here, even though SHAP is introduced as an interpretation approach applicable more broadly. section 6.4.3

How Build AI Drug Discovery Pipelines covers it

How deep it goes
Defines sensitivity analysis and works through numerical partial derivatives and SHAP visualizations, while referring readers elsewhere for further detail.
Examples
Uses a ROBIN RNA binder for descriptor derivatives and an XGBoost classifier for SHAP plots.
What you can do after
Apply interpretation via SHAP and numerical perturbations to examine descriptor effects on predictions.
How it connects
Connects feature importance with sensitivity analysis, partial derivatives, surrogate models, and Shapley values.

Also explained in

Compare how 2 books explain model-agnostic method →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build AI Drug Discovery Pipelines. The section links point to the parts of the book it draws on.