Before you can read Feature attribution (SHAP, LIME), you need to already see a handful of symbols and ideas. The parent page throws around f, x, ϕi, πx, subsets S, expectations E, and the word "baseline." This page builds each one from nothing, in an order where every symbol is earned before it is used.
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 (x1,…,x4) feed arrows into a central box labelled f; one arrow leaves it to a single output f(x)=0.72. Use it to see that many inputs collapse to one number — which is exactly the number attribution will later split back apart.
WHY we need this notation. Attribution asks "how much did slot i matter?" You cannot ask that without a name for each slot (xi), for the whole list (x), and for the machine (f). The subscript i is just a house number so we can point at one feature.
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 {1,3}, and the full set. Use it to see that a subset S is just one on/off pattern, and that there are 2d such patterns — the count that makes exact SHAP expensive.
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 S" means in the Shapley formula.
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 E.
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:
fS(xS)=E[f(X)XS=xS]
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 f and the outputs are averaged into fS(xS). Use it to see why a hidden feature becomes an average, not a zero.
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 +0.52 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.
The building block of ϕi is one small measurement:
Figure s04 — the marginal-gain staircase. Predictions climb 0.20→0.35→0.40→0.58→0.72 as credit, income, debt, age are switched on one at a time; each riser is labelled with its Δi(S). Use it to see that the four gains stack to fill the whole +0.52 gap.
WHY average over many S? From the loan example, adding "debt" gave +0.18 in one ordering. In a different ordering (different S already on) it gives a different jump. A fair score cannot depend on the accident of ordering, so ϕi is the average jump over all subsets S that don't already contain i — with combinatorial weights that count how many orderings produce each S. Written out fully:
LIME needs one more idea: closeness. It builds a simple model that is accurate only nearx.
WHY the exponential? We want a smooth dial that is 1 at the centre and fades to 0 as things get far — never negative, never jumping. e−(distance2) 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 g by minimising a πx-weighted squared error, so perturbations near x 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 x badly. ::: Weighting by πx forces the fit to be accurate where we are asking the question — right around x.
Both roads end at the same place: split f(x)−ϕ0 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).
Test yourself — say the answer aloud before revealing.
What does xi mean, and how does it differ from x?
xi is the value in slot i (one feature); x is the whole list of feature values for one instance.
What is d?
The number of features (slots) in the input.
What does a subset S represent?
The set of features currently "known" / switched on; the rest are hidden.
What does ∣S∣ count, and what is ∅?
∣S∣ counts how many features are switched on; ∅ is the empty coalition — nothing known.
How many possible subsets are there, and why does it matter?
2d (each feature on or off); this is why exact SHAP is expensive.
Why do we fill hidden features with a conditional expectation instead of 0?
Zero is a real value the model reacts to; true absence means "averaged over plausible values, given the known ones," which is E[f(X)∣XS=xS].
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 XS=xS.
What does fS(xS) mean in one sentence?
The prediction when only the features in S are known and the rest are averaged out given the known ones.
What are ϕ0 and f(x), and what is "the gap"?
ϕ0 is the average prediction (no features known); f(x) is this instance's prediction; the gap f(x)−ϕ0 is what attribution must explain.
What is Δi(S), and why is it a difference?
The jump from adding feature i to coalition S; the difference cancels everything caused by S, leaving only i's effect.
Write the Shapley value ϕi with its weights.
ϕi=∑S⊆N∖{i}d!∣S∣!(d−∣S∣−1)!Δi(S).
What does the efficiency axiom guarantee about ∑iϕi?
It equals f(x)−ϕ0 exactly — no leftover residual.
Where does πx enter LIME?
It weights the squared errors in the local least-squares fit argming∑zπx(z)[f(z)−g(z)]2+Ω(g), so near points dominate.
Why an exponential for πx?
It gives a smooth bubble that is 1 at the centre and fades to 0, never negative.