6.3.2 · D1Interpretability & Explainability

Foundations — Feature attribution (SHAP, LIME)

2,776 words13 min readBack to topic

Before you can read Feature attribution (SHAP, LIME), you need to already see a handful of symbols and ideas. The parent page throws around , , , , subsets , expectations , and the word "baseline." This page builds each one from nothing, in an order where every symbol is earned before it is used.


1. The model as a machine: and

Start with the most basic picture. A model is a machine with slots. You drop numbers into the slots, turn the crank, and one number comes out.

Figure s01 — the machine picture. Four coloured slot-boxes () feed arrows into a central box labelled ; one arrow leaves it to a single output . Use it to see that many inputs collapse to one number — which is exactly the number attribution will later split back apart.

Figure — Feature attribution (SHAP, LIME)

WHY we need this notation. Attribution asks "how much did slot matter?" You cannot ask that without a name for each slot (), for the whole list (), and for the machine (). The subscript is just a house number so we can point at one feature.


2. Turning slots on and off: subsets

Attribution keeps asking "what if this feature weren't there?" So we need a way to talk about which slots are switched on.

Figure s02 — switches as coalitions. Three rows of four circular switches (green = on, grey = off) show the empty coalition , a partial coalition , and the full set. Use it to see that a subset is just one on/off pattern, and that there are such patterns — the count that makes exact SHAP expensive.

Figure — Feature attribution (SHAP, LIME)

WHY we need subsets. A feature's importance depends on its company. Credit score matters a lot when income is unknown, but less when income is already revealed. To measure this honestly we must try the feature in every possible group of companions — that is exactly what "for all subsets " means in the Shapley formula.


3. The "hidden slot" problem: expectation

Machines demand a number in every slot. But when a feature is "hidden," what do we feed it? We cannot leave the slot empty and we should not feed a fake zero.

WHY averaging is the right "fill-in." To hide a feature, we replace it not with a single guess but with all the values it could plausibly take, blended by their frequency. If we hid "income," we ask: "averaging over the incomes typical of this population, what does the model say?" That blended answer is written with .

The honest way to write this fixes the known slots at their real values and averages only the hidden ones — conditioned on what we already know:

Let us decode every piece, since the parent uses this line without unpacking it:

Figure s03 — averaging fills the hidden slot. Two slots (credit, income) are fixed; several draws of the hidden slots (debt, age) — drawn consistently with the known values — each run through and the outputs are averaged into . Use it to see why a hidden feature becomes an average, not a zero.

Figure — Feature attribution (SHAP, LIME)

4. Two anchor predictions: baseline and full

Every attribution measures a journey between two numbers.

WHY a baseline at all? "This applicant has 72% risk" is meaningless without a reference. Attribution explains the deviation from average: the features must, together, account for the whole climb from the crowd's average to Bob's number. That "together account for exactly the gap" is the efficiency promise on the parent page.


5. The credit slice: and the marginal gain

Now the star symbol.

The building block of is one small measurement:

Figure s04 — the marginal-gain staircase. Predictions climb as credit, income, debt, age are switched on one at a time; each riser is labelled with its . Use it to see that the four gains stack to fill the whole gap.

Figure — Feature attribution (SHAP, LIME)

WHY average over many ? From the loan example, adding "debt" gave in one ordering. In a different ordering (different already on) it gives a different jump. A fair score cannot depend on the accident of ordering, so is the average jump over all subsets that don't already contain — with combinatorial weights that count how many orderings produce each . Written out fully:


6. "Local neighbourhood" and the weight (for LIME)

LIME needs one more idea: closeness. It builds a simple model that is accurate only near .

WHY the exponential? We want a smooth dial that is at the centre and fades to as things get far — never negative, never jumping. is the standard "soft bubble" shape (a bell) that does exactly this. It is the reason LIME "only cares about fidelity in the local region."

Now we can see where the weight actually enters: LIME fits a simple linear model by minimising a -weighted squared error, so perturbations near dominate the fit:

Recall Why not just use every sample equally?

Because a linear model that fits far-away points well may fit the region around badly. ::: Weighting by forces the fit to be accurate where we are asking the question — right around .


How the foundations feed the topic

Model f and input x

Slots x_i and count d

Subsets S switches on and off

Conditional expectation E fills hidden slots

Baseline phi0 and target f of x

Marginal gain Delta i of S

Shapley value phi i fair credit

SHAP

Proximity weight pi x

Weighted local linear fit

LIME

Both roads end at the same place: split into per-feature pushes. Related tools that reuse these ideas: 5.4.02-Permutation-importance (global cousin of attribution), 3.5.04-Tree-ensembleinterpretation (where TreeSHAP lives), 6.2.03-Attention-mechanisms (a different "what mattered" signal), and 6.3.03-Counterfactual-explanations (the "what would flip it" sibling).


Equipment checklist

Test yourself — say the answer aloud before revealing.

What does mean, and how does it differ from ?
is the value in slot (one feature); is the whole list of feature values for one instance.
What is ?
The number of features (slots) in the input.
What does a subset represent?
The set of features currently "known" / switched on; the rest are hidden.
What does count, and what is ?
counts how many features are switched on; is the empty coalition — nothing known.
How many possible subsets are there, and why does it matter?
(each feature on or off); this is why exact SHAP is expensive.
Why do we fill hidden features with a conditional expectation instead of ?
Zero is a real value the model reacts to; true absence means "averaged over plausible values, given the known ones," which is .
What is the difference between marginal and conditional filling of hidden slots?
Marginal draws hidden features independently and can create impossible combinations; conditional keeps them consistent with the known features .
What does mean in one sentence?
The prediction when only the features in are known and the rest are averaged out given the known ones.
What are and , and what is "the gap"?
is the average prediction (no features known); is this instance's prediction; the gap is what attribution must explain.
What is , and why is it a difference?
The jump from adding feature to coalition ; the difference cancels everything caused by , leaving only 's effect.
Write the Shapley value with its weights.
.
What does the efficiency axiom guarantee about ?
It equals exactly — no leftover residual.
Where does enter LIME?
It weights the squared errors in the local least-squares fit , so near points dominate.
Why an exponential for ?
It gives a smooth bubble that is 1 at the centre and fades to 0, never negative.