Responsible AI & Behavioural

Explainability: SHAP & LIME

Opening the black box: how game theory guarantees mathematically sound feature attribution in ML.

🟡 intermediate4 min readinterpretabilitymust-know
SHAP (SHapley Additive exPlanations) and LIME provide post-hoc model-agnostic explainability. SHAP is grounded in cooperative game theory, guaranteeing four essential axioms (Efficiency, Symmetry, Dummy, Additivity). SHAP computes a feature's marginal contribution across all feature subsets, ensuring local attributions sum up to (Model Output - Base Expected Value). TreeSHAP optimizes this to O(TL D²) for decision trees.

Shapley values from game theory

Consider a predictive model as a cooperative game where features are players collaborating to produce a prediction (payout f(x)).

The Shapley Value ϕ_i of feature i is its average marginal contribution across all possible feature subsets S ⊆ F \ {i}:

ϕ_i = ∑_{S ⊆ F \ {i}} [ |S|! (|F| - |S| - 1)! / |F|! ] · [ f(S ∪ {i}) - f(S) ]

The 4 Mandatory Axioms

  1. Efficiency: ∑_{i=1}^M ϕ_i = f(x) - E[f(x)] (attributions sum to difference from baseline).
  2. Symmetry: If features i and j contribute identically to all subsets, ϕ_i = ϕ_j.
  3. Dummy (Null player): If feature i changes no predictions, ϕ_i = 0.
  4. Additivity: For ensemble f + g, ϕ_i(f + g) = ϕ_i(f) + ϕ_i(g).

SHAP vs LIME

FeatureSHAPLIME
Theoretical FoundationGame Theory (Shapley Values)Local Linear Surrogate Modeling
Consistency & FairnessGuaranteed by AxiomsNo theoretical guarantees (sampling noise)
Local Sum Property∑ ϕ_i = f(x) - E[f(x)]Does not sum to prediction
Computation SpeedSlow for KernelSHAP, Fast for TreeSHAP (O(TL D²))Fast (Local sampling around point)
Global InterpretabilityYes (mean absolute SHAP across samples)No (Purely local explanations)

Global vs Local Interpretability

Say this out loud

"SHAP is the gold standard for model explainability because it is mathematically grounded in Shapley game theory. Unlike GBDT gain or LIME, SHAP guarantees the Efficiency axiom — meaning local feature attributions add up exactly to the difference between the model's prediction and the expected base rate. For tree models, TreeSHAP computes exact Shapley values in polynomial time."

Follow-ups to expect

Check yourself

Question 1 of 3

What core property guarantees that the sum of all SHAP feature attribution values for a prediction equals (Prediction - Expected Base Value)?

More in Responsible AI & Behavioural

See all →
Telling Your ML Project Story5 minBias & Fairness in ML5 minExplaining a Model to a Non-Technical Exec5 min