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.
Operating Rules
- Explain a fixed, evaluated model; do not use SHAP as a substitute for predictive validation.
- Use held-out or clearly labeled analysis rows for explanations. Choose background rows only from an appropriate training or reference population.
- State the explained output: regression value, raw margin, probability, log loss, logit, or another model method.
- Keep explanations as
shap.Explanationobjects. Callexplainer(X); use.shap_values(X)only when maintaining legacy code. - For multi-output models, select one output before using tabular plots:
explanation[..., output_index]. - Check
base_values + values.sum(...)against the exact model output being explained. - Treat SHAP as a description of model behavior under a masking/background choice. It does not establish causality, fairness, recourse, or scientific mechanism.
- Never silence an additivity failure until input shape, preprocessing, model version, output space, and row ordering have been checked.
- Do not load untrusted pickle, joblib, model, or explainer artifacts; those formats can execute code during deserialization.