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

