Part XXI — Explainable AI & Model Interpretability · Chapter 9

Explain one prediction three ways

Hook

Four chapters, four different answers to "why did the model say that." Applied to the exact same house, the exact same linear model, do they actually agree with each other — or is each one answering a subtly different question?

Intuition

Same house from Chapter 6: size 2525, age 55, distance 88, renovated. Switch lenses. Saliency reports the raw weight magnitudes — the same four numbers no matter which house you ask about. SHAP — short for SHapley Additive exPlanations — reports each feature's actual pull on this house's price, relative to a typical one. Counterfactual reports something else again: how much each feature would have to move to flip an approve/deny decision.

Formalize

All three read the same four weights ww, but ask three different questions:

saliencyi=wi,SHAPi=wi(xixˉi),Δcf=f(x)w2w\text{saliency}_i = |w_i|, \qquad \text{SHAP}_i = w_i(x_i-\bar x_i), \qquad \Delta^{\text{cf}} = -\frac{f(x)}{\lVert w \rVert^2}\,w
  • saliencyi\text{saliency}_i — feature ii's raw sensitivity: the magnitude of its weight, the same for every input.
  • wiw_i — the linear model's weight for feature ii.
  • SHAPi\text{SHAP}_i — feature ii's actual contribution to this specific house's prediction.
  • xix_i — this house's actual value for feature ii.
  • xˉi\bar x_i — feature ii's baseline (typical) value.
  • Δcf\Delta^{\text{cf}} — the counterfactual edit: how much each feature would need to change to flip the decision.
  • f(x)f(x) — the model's prediction for input xx.
  • ww — the full weight vector.
  1. Saliency: sensitivity in general

    Saliency answers "how sensitive is the output to this feature, in general."

  2. SHAP: this instance's actual pull

    SHAP answers "how much did this feature's actual value move this prediction away from typical."

  3. Counterfactual: the cheapest edit

    Counterfactual answers "what's the cheapest edit that changes the decision."

  4. Different questions, not competing answers

    None of them is wrong — they're just not the same question, and mixing them up is a real, common mistake.

Play

Compare this house to the baseline house — a very different prediction, 445445 versus 320320. Saliency's bars don't move at all: they never looked at either house's actual values, only the model's fixed weights. SHAP's bars do move, because SHAP's entire job is measuring how far this instance sits from typical.

Worked example

This house predicts 445445; call anything below a 500500 threshold "not yet approved" for this exercise:

  1. Saliency says renovated matters most

    w=(15,2,5,20)|w| = (15, 2, 5, 20) for size, age, distance, renovated — renovated's raw sensitivity is the largest of the four, and that ranking would be identical for every house this model ever sees.

  2. SHAP ranks size highest instead

    Size dominates here:

    • Size contributes 7575 to the SHAP value, and this house's size is 55 units above baseline
    • Renovated contributes 2020 to the SHAP value, and this house's renovated status only differs by 11
  3. The counterfactual finds a different answer again

    This house's prediction is 445445, so f(x)=445500=55f(x) = 445-500 = -55 below the threshold. The weight vector's squared norm is w2=152+(2)2+(5)2+202=225+4+25+400=654\lVert w \rVert^2 = 15^2+(-2)^2+(-5)^2+20^2 = 225+4+25+400=654, giving a scale factor of 55/6540.0841-55/654\approx-0.0841. Each feature's delta is scale×wi-\text{scale}\times w_i:

    • Size: 0.0841×15+1.260.0841\times15\approx+1.26
    • Age: 0.0841×20.17-0.0841\times2\approx-0.17
    • Distance: 0.0841×50.42-0.0841\times5\approx-0.42
    • Renovated: 0.0841×20+1.680.0841\times20\approx+1.68

    That last number is a real problem: renovated is a 0/10/1 feature, and 1.681.68 isn't a valid value for it. The naive closed form doesn't know that "renovated" can't be anything other than 00 or 11.

Checkpoint

Age sits exactly at its baseline value in some hypothetical house. Which lens would show age contributing exactly zero in that case?

Pick a lens to try it
Summary
saliencyi=wi,SHAPi=wi(xixˉi),Δcf=f(x)w2w\text{saliency}_i = |w_i|, \qquad \text{SHAP}_i = w_i(x_i-\bar x_i), \qquad \Delta^{\text{cf}} = -\frac{f(x)}{\lVert w \rVert^2}\,w

Every explanation technique in this part traces back to the same handful of ideas from earlier in the course: a derivative (saliency, Grad-CAM — short for Gradient-weighted Class Activation Mapping), a weighted local fit (LIME — short for Local Interpretable Model-agnostic Explanations), a fair game-theoretic split (Shapley, SHAP), and a gradient step toward a boundary (counterfactuals). None of them is "the" explanation — each answers a genuinely different question about the same model, and picking the right one means knowing which question you're actually asking. That's the real skill this part was building toward: not running an explainability library, but knowing what its output does and doesn't tell you. Explainability comes back for a second, deeper pass later in the course, once there are less transparent models — and a wider roster of architectures — actually worth auditing.