6.3.10 · D1Interpretability & Explainability

Foundations — Counterfactual explanations

3,713 words17 min readBack to topic

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.


0. The scene: a model that says yes or no

Before any symbol, picture the situation. A bank has a machine. You feed it facts about a person; it prints APPROVED or DENIED.

Everything below is just careful notation for "the input", "the machine", and "the answer".


1. The vector — a bundle of numbers with an address

The parent writes . Let's earn every piece.

So for our loan applicant:

What the figure shows: two axes — income (feature ) horizontal, credit score (feature ) vertical. A black dot sits at labelled , with dashed guide lines dropping to each axis so you can read its two coordinates. A red dot at labelled 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 near the first. To say "near" you first need "point". No vector, no notion of distance, no counterfactual.


2. The prime mark — "the edited version"

Here only slot 1 changed (). 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 . We need a name that says "not the original, the proposed edit" without inventing a new letter each time.


3. The function — the machine as a symbol

Decode that arrow notation:

Sometimes outputs not a hard but a probability between and (the parent's "probability 0.35"). Read as the machine's confidence that the answer is 1. The rule: if call it class 1, else class 0.

Why the topic needs this. A counterfactual is defined by — the machine's output must flip. We can't state "flip the answer" without a name for "the answer": that name is .


4. Distance and norms — how far apart two points are

We want close to . "Close" needs a number.

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 ") and a black target dot up-and-right at (labelled "target "). The horizontal axis is "change in feature 1", the vertical axis "change in feature 2". A black diagonal straight line connects them — the route that alters both features at once. A red two-segment path goes fully right along the bottom then straight up — the (city-block) route that spends its whole budget on one feature before touching the other. This is the visual argument for why produces sparse edits.

The figure shows why the parent prefers for tabular data. To reach a diagonal target, (city-block, red path) is happiest going straight along one axis — it likes changing one feature a lot and leaving others at zero. (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 wins.

Why the topic needs this. "Minimal change" is meaningless until you pick a ruler. The norm is that ruler.


4b. Categorical and discrete features — the edge case

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".


5. Argmin, min, and — the language of "find the best edit"

The parent's central formula is an . 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:

"Among all valid candidate points , hand me the one that is closest, flips the answer, and stays realistic — traded off by the dials ." (The plausibility term is defined precisely in §8.)

Why the topic needs this. Three goals fight each other. + weighted loss is exactly the grammar for "satisfy competing goals, best compromise wins".


6. The decision boundary — where the answer flips

For a simple linear model the parent writes (recall from §3 that means approve, means deny, and the thing inside is the score ). Decode:

The fence itself is the set of points where the score is exactly zero: .

What the figure shows: a black straight line cutting diagonally across the plane — the decision boundary . The upper-left region is labelled "APPROVE side", the lower-right "DENY side". A black dot sits in the DENY region. A red arrow leaves and strikes the boundary at a right angle (a small square marks the corner), landing on the red target point — 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:

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.


7. The gradient — the compass pointing uphill

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 , repeatedly step downhill on until the prediction flips. , the minus, and are the three pieces of that step.


8. Plausibility and constraints — staying on planet Earth

We must actually pick a formula for . Three concrete, commonly-used choices:


How the foundations feed the topic

vector x = a person as a point

prime x' = edited copy

function f = the model answer

norm = how big the edit

categorical one-hot = discrete features

decision boundary = where answer flips

loss L with weights lambda gamma

gradient nabla = walk downhill to boundary

plausibility P and clip = stay realistic

Counterfactual explanation

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.


Equipment checklist

Cover the right side and answer each. If any stumps you, reread its section before the parent note.

What does the bold letter stand for, in one