SHAP

Exact Shapley values are beautifully principled and brutally expensive. SHAP provides practical approximations and a common additive explanation format.

Kernel SHAP samples feature coalitions, gets a black-box prediction for each one, and fits a weighted linear model. The fitted coefficients estimate the Shapley values.

Additive explanation

SHAP writes a prediction as:

f(x)=ϕ0+j=1pϕjf(x)=\phi_0+\sum_{j=1}^{p}\phi_j

ϕ0\phi_0 is the baseline prediction and each ϕj\phi_j is a signed contribution. Positive and negative attributions reconcile exactly with the explained output under the chosen SHAP method.

Kernel SHAP — Step by Step

Walk through each stage of Kernel SHAP for a single loan applicant. The algorithm approximates Shapley values by fitting a weighted linear regression over feature coalition samples.

Step 1 — Sample Coalitions

We enumerate subsets of features — called coalitions — where each feature is either present (1) or absent (0). For 3 features there are 8 possible subsets. In practice, Kernel SHAP samples a random subset of these when the feature count is large.

Instance being explained

income = highdebt = lowhistory = goodprediction = 0.82
Coalition mask
incomedebthistory
+ 7 more coalitions...

Progress

1Sample Coalitions
2Get Predictions
3Compute Weights
4Fit Linear Model
5Read Shapley Values
Kernel SHAP is model-agnostic and approximates Shapley values with any black-box model. The SHAP kernel gives full and empty coalitions extreme weights to satisfy the Shapley axioms.

Reading SHAP Plots

SHAP values can be visualized in three main ways. Each plot answers a different question — use the tabs to explore them.

A force plot explains one prediction. Features push the output right (positive, red) or left (negative, blue) from a shared baseline. The final prediction is where the forces balance.

Baseline 0.50Prediction 0.82
0.50
+0.18
+0.10
+0.10
-0.06
pushes prediction up pushes prediction down

income=high

+0.18

history=good

+0.10

employed=yes

+0.10

debt=low

-0.06

Hover a feature to interpret its contribution.

Reading rule: positive (red) bars push the prediction rightward above baseline. The total displacement equals 0.380.06 = +0.32, reconciling baseline 0.50 to prediction 0.82.
Force plots explain one prediction. Beeswarm plots reveal patterns across all examples. Dependence plots show how a single feature's impact changes with its value.
Checkpoint

Why might two correlated features each receive a smaller SHAP value than expected?