Quant Memo
Core

Counterfactual Explanations

Instead of scoring how much each feature mattered, a counterfactual explanation just answers "what's the smallest change to this case that would have flipped the model's decision?" — often the more actionable question.

Prerequisites: Intrinsically Interpretable vs Post-Hoc Explained Models

A credit model rejects a loan applicant. A SHAP explanation can tell you that debt-to-income was the largest negative contributor to the decision. That is useful for an auditor, but it is not directly useful to the applicant, who wants to know something more specific: what would it actually take to get approved? A counterfactual explanation answers exactly that — not "which features mattered," but "what is the smallest, most realistic change to this case that would have flipped the model's output."

The idea

Formally, given an input xx that the model classified one way, a counterfactual explanation finds a nearby point xx' that the model classifies the other way, where "nearby" is measured by how small and how realistic the change from xx to xx' is. Instead of decomposing the existing prediction, it searches for the closest different case. "If your debt-to-income ratio had been 5 points lower, this application would have been approved" is a counterfactual explanation. It says nothing about how much debt-to-income "contributed" in the abstract — it names a concrete, checkable alternative.

Worked example

A trading-risk model flags an order as "high risk of adverse selection" and blocks it. Feature values for this order: size = 50,000 shares, participation rate = 18% of expected daily volume, spread at submission = 4 basis points. The model's decision boundary, explored around this point, shows the order would have been cleared if participation rate had been reduced to 11% (holding size and spread fixed) — a 7-point drop is the smallest single-feature change that flips the decision. Alternatively, holding participation rate fixed, the order clears if the spread at submission had been 2.5 basis points or tighter. Both are valid counterfactuals; a trading desk can act on either one directly: split the order to cut participation rate, or wait for a tighter spread. Neither requires understanding the model's internals at all — the counterfactual is a recipe, not an attribution.

rejected region approved region original order counterfactual smallest realistic step across the boundary
The counterfactual is the nearest point on the other side of the model's decision boundary — not a description of the original point's internals, but a description of the closest different case.

A counterfactual explanation is defined by two things: it must actually flip the model's decision, and it must be as small and as realistic as possible. An explanation that changes ten features by huge amounts technically flips the decision too, but it is not useful — the search specifically wants the minimal, plausible edit.

Why "realistic" is the hard part

The naive version of this search — perturb every feature until the model's output flips, then report whichever perturbation is numerically smallest — routinely produces nonsense: "you would have been approved if your age had been −4," or a counterfactual that requires debt-to-income to drop while income stays fixed and debt magically vanishes, ignoring that the two are mechanically linked. Usable counterfactual methods constrain the search to changes that are actually achievable (only allow features a person could plausibly alter, in directions that respect real-world relationships between features) and penalise the size of the edit, not just count the number of features touched.

Where quants meet this

Beyond credit and trading-risk gates, counterfactuals are useful anywhere a model-driven decision needs to come with actionable recourse — a margin call triggered by a risk model ("posting $50,000 more collateral would have avoided this call"), a KYC or fraud flag review, or explaining to a client why a robo-advisor rebalanced them out of a position. They are also a debugging tool for the model builder: if the smallest counterfactual for a rejected loan is an implausible change to an unrelated feature, that is a sign the model has latched onto something spurious, the same kind of check discussed under Confounding in Financial Data.

A counterfactual explanation describes the model's decision boundary, not necessarily the real world's causal structure. "Increasing collateral by $50,000 would have cleared this flag" is a true statement about what the model would output — it is only a trustworthy statement about what would actually happen if the features involved are ones the model relates to the outcome causally rather than merely correlationally. Treat a counterfactual as a description of the model first, and a real-world recommendation second.

Multiple valid counterfactuals, and why that's useful

A single case typically has many different counterfactuals — reduce participation rate, or tighten the spread, in the earlier trading example — and modern counterfactual methods usually generate several rather than stopping at the first one found. This is not redundancy; different counterfactuals can require changing entirely different, non-overlapping sets of features, and presenting several gives the person on the receiving end actual choice about which lever is easiest for them to pull. It also serves as a robustness check on the explanation itself: if every counterfactual method converges on changing the same one or two features no matter how the search is initialised, that is much stronger evidence those features are genuinely decisive than a single run finding a single answer.

Actionability constraints

Not every feature a model uses is something an individual can actually change, and a useful counterfactual search has to respect that distinction explicitly. Age, past bankruptcy history, and structural account attributes are typically fixed; income, debt levels, and order size are typically actionable. Search algorithms that ignore this can return technically-correct but useless counterfactuals — "you would have been approved if you were five years older" — so production implementations constrain the search to only propose changes along features flagged as mutable, and often further constrain the direction of change (income can realistically go up over time, but rarely by an implausibly large jump within a short horizon). Getting this constraint list right is itself a domain-knowledge exercise, not something the optimisation can infer on its own.

Related concepts

Practice in interviews

Further reading

  • Wachter, Mittelstadt & Russell, Counterfactual Explanations Without Opening the Black Box (2017)
  • Molnar, Interpretable Machine Learning, ch. 9.3
ShareTwitterLinkedIn