← AI Terminology
SHAP / LIME
SHAP (SHapley Additive exPlanations) and LIME (Local Interpretable Model-agnostic Explanations) are post-hoc explainability methods that estimate each input feature's contribution to a specific model prediction — making black-box model decisions interpretable without modifying the model.
They are the two most widely used explainability techniques in production ML.
They are the two most widely used explainability techniques in production ML.
Why It Matters in AI
Regulators (GDPR's "right to explanation", ECOA in credit decisions) and high-stakes users (doctors, loan officers) need to understand why a model made a specific prediction. SHAP provides theoretically principled feature attributions based on game theory (Shapley values); LIME approximates local model behaviour with an interpretable surrogate. Both convert "the model said 67% fraud" into "the transaction amount (+0.21), unusual merchant (-0.08), and new device (+0.15) drove this prediction."
Key Points
| Aspect | Description |
|---|---|
| LIME | Perturb inputs around one example, fit a local linear model — approximation, faster for text/images |
| TreeSHAP | Exact, fast SHAP for tree models (XGBoost, LightGBM, sklearn trees) — milliseconds per prediction |
| Kernel SHAP | Model-agnostic SHAP for any model via sampling — slower, works anywhere |
| SHAP values | Feature contributions summing to the prediction − baseline — game-theoretically optimal attribution |
| Model-agnostic | Both work on any model: neural networks, gradient boosting, random forests, LLMs |
| Global vs local | SHAP aggregated over all examples → global feature importance; per-example → local explanation |
Simple Analogy
A legal consultant explaining a court verdict to a client: instead of "you lost because the model said so," they explain "the unpaid invoice (+40%), late delivery history (+25%), and contract ambiguity (-5%) drove the decision." SHAP/LIME are the consultants — they translate model decisions into human-readable evidence weights.
Common Usage Examples
import shap; explainer = shap.TreeExplainer(xgb_model); values = explainer.shap_values(X_test)shap.summary_plot(shap_values, X_test)— beeswarm plot of feature impacts across all test samplesshap.force_plot(explainer.expected_value, values[0], X_test.iloc[0])— single prediction waterfall- LIME text:
lime.lime_text.LimeTextExplainer().explain_instance(text, classifier.predict_proba) shap.Explainer(model)(X_test)— unified API for SHAP across model types (v0.40+)
Summary
In short: SHAP and LIME are the standard post-hoc explainability tools — translating black-box model predictions into per-feature contribution scores, enabling regulatory compliance and human-understandable AI decisions.