shap

Installation
SKILL.md

SHAP

Use SHAP to describe how a fitted predictive model maps inputs to outputs. Work from the modern shap.Explanation API, make the explained output and background distribution explicit, and validate every explanation before interpreting it.

This skill is aligned with SHAP 0.52.0 (released 2026-05-28). That release requires Python 3.12 or newer.

The maintained examples were checked on Python 3.12.10 with SHAP 0.52.0, NumPy 2.5.3, pandas 3.0.6, scikit-learn 1.9.1, and matplotlib 3.11.2. Native tests cover small tree, exact, permutation, partition, linear, additive, kernel, text, and constant-image games; additional numeric XGBoost 3.4.1 smoke checks cover raw, probability, loss, and interaction outputs. Reference snippets that require a project model, framework, or data are adaptation templates; optional pretrained/deep, GPU, and distributed integrations remain illustrative and require their own runtime validation.

Operating Rules

  1. Explain a fixed, evaluated model; do not use SHAP as a substitute for predictive validation.
  2. Use held-out or clearly labeled analysis rows for explanations. Choose background rows only from an appropriate training or reference population.
  3. State the explained output: regression value, raw margin, probability, log loss, logit, or another model method.
  4. Prefer shap.Explanation objects and explainer(X). Some specialized options still require .shap_values(X), including deep ranked outputs, gradient sampling budgets, and Kernel SHAP nsamples. Preserve their output indexes and baselines explicitly.
  5. For multi-output models, select one output before using tabular plots: explanation[..., output_index].
  6. Check base_values + values.sum(...) against the exact model output being explained.
  7. Treat SHAP as a description of model behavior under a masking/background choice. It does not establish causality, fairness, recourse, or scientific mechanism.
  8. Never silence an additivity failure until input shape, preprocessing, model version, output space, and row ordering have been checked.
  9. Do not load untrusted pickle, joblib, model, or explainer artifacts; those formats can execute code during deserialization.
Installs
1.8K
GitHub Stars
48.2K
First Seen
Jan 20, 2026