This is the prerequisite page for Counterfactual explanations (6.3.10). The parent note throws a lot of notation at you very fast — vectors, norms, gradients, decision boundaries, Lagrange multipliers. Here we build each symbol from nothing, in the order they depend on each other, with a picture for every one.
What the figure shows: two axes — income (feature x1) horizontal, credit score (feature x2) vertical. A black dot sits at (45,680) labelled x, with dashed guide lines dropping to each axis so you can read its two coordinates. A red dot at (52,680) labelled x′ sits directly to the right at the same height — same credit, higher income. The picture makes the point literal: a person is a single dot, and editing one feature slides the dot along one axis.
Why the topic needs this. A counterfactual is a second point x′ near the first. To say "near" you first need "point". No vector, no notion of distance, no counterfactual.
Here only slot 1 changed (45→52). The prime never means multiply or derivative in this topic — it always means "the candidate counterfactual".
Why the topic needs this. The whole page is a hunt for the best x′. We need a name that says "not the original, the proposed edit" without inventing a new letter each time.
Sometimes f outputs not a hard 0/1 but a probabilityp between 0 and 1 (the parent's "probability 0.35"). Read p as the machine's confidence that the answer is 1. The rule: if p>0.5 call it class 1, else class 0.
Why the topic needs this. A counterfactual is defined by f(x′)=f(x) — the machine's output must flip. We can't state "flip the answer" without a name for "the answer": that name is f.
Now we squeeze that list of changes into a single "how big was the edit" number. Two common ways:
What the figure shows: a black start dot at the origin (labelled "start x") and a black target dot up-and-right at (4,3) (labelled "target x′"). The horizontal axis is "change in feature 1", the vertical axis "change in feature 2". A black diagonal straight line connects them — the L2 route that alters both features at once. A red two-segment path goes fully right along the bottom then straight up — the L1 (city-block) route that spends its whole budget on one feature before touching the other. This is the visual argument for why L1 produces sparse edits.
The figure shows why the parent prefers L1 for tabular data. To reach a diagonal target, L1 (city-block, red path) is happiest going straight along one axis — it likes changing one feature a lot and leaving others at zero. L2 (diagonal, black) spreads the change across several features. For a loan you want a clean story ("raise income by $7k") not "nudge all six features a little", so L1 wins.
Why the topic needs this. "Minimal change" is meaningless until you pick a ruler. The norm is that ruler.
Not every feature is a smooth number. "Employment type" is one of {salaried, self-employed, unemployed}; "has a degree" is yes/no. You cannot ask an optimizer to "add 0.3 of a category". Here is how the topic handles it.
Why the topic needs this. Loan, hiring, and medical data are mostly tabular with many categorical columns. A counterfactual method that only knows continuous numbers would produce nonsense edits like "become 0.4 self-employed".
The parent's central formula is an argmin. Let's build it.
Now the "did it flip?" term needs a precise form. There are two honest ways to write it:
So the parent's objective reads, in English:
x′=argminz∈Xvalid[stay close∥z−x∥1+λ⋅turn the answerhinge(f(z))+γ⋅stay realisticP(z)]
"Among all valid candidate points z, hand me the one that is closest, flips the answer, and stays realistic — traded off by the dials λ,γ." (The plausibility term P is defined precisely in §8.)
Why the topic needs this. Three goals fight each other. argmin + weighted loss is exactly the grammar for "satisfy competing goals, best compromise wins".
For a simple linear model the parent writes f(x)=sign(w⊤x+b) (recall from §3 that +1 means approve, −1 means deny, and the thing inside sign is the score s=w⊤x+b). Decode:
The fence itself is the set of points where the score is exactly zero: w⊤x+b=0.
What the figure shows: a black straight line cutting diagonally across the plane — the decision boundary w⊤x+b=0. The upper-left region is labelled "APPROVE side", the lower-right "DENY side". A black dot x sits in the DENY region. A red arrow leaves x and strikes the boundary at a right angle (a small square marks the 90° corner), landing on the red target point xboundary — the nearest place the answer flips. The arrow is perpendicular to the fence, which is the visual heart of the derivation below.
Here is the geometric reasoning, step by step, for the parent's closest-boundary formula.
Putting that step length back in gives the parent's formula:
xboundary=x−∥w∥2w⊤x+bw.
That red landing point is the counterfactual for a linear model — the nearest place the answer changes.
Why the topic needs this. The geometry section of the parent is entirely "how do I reach the fence with the shortest hop?". Boundary + perpendicular arrow is the picture behind every formula there.
For real (nonlinear) models there's no clean formula; we walk to the boundary. The tool for walking is the gradient.
Why the topic needs this. "Gradient-based (Wachter et al.)" is the workhorse method. It literally means: start at x, repeatedly step downhill on L until the prediction flips. ∇, the minus, and α are the three pieces of that step.
Read top to bottom: points and edits give you distance; categoricals fit into the same space; the model gives you the boundary; loss packages the three goals; the gradient walks you across; plausibility keeps it real. Their meeting point is the counterfactual.