Computing Library › Machine Learning
Machine Learning

Counterfactual Explanations

A counterfactual explanation states the smallest change to an input that would flip the model decision.

What would have to change

A counterfactual explanation answers a practical, human question: what is the smallest change to this input that would produce a different outcome? For a rejected loan application, it might be that raising income by a modest amount would flip the decision. Rather than assigning credit to features, counterfactuals give actionable recourse, telling a person what to do differently.

The optimization

Kronos motion — lego machine

Finding a counterfactual is an optimization: search for an input x-prime close to the original x that the model classifies as the desired class. The objective trades off two goals, x-prime must achieve the target prediction, and it must stay close to x under a distance that reflects plausibility and effort. Constraints keep changes realistic, holding immutable features fixed and respecting valid ranges.

Strengths

Counterfactuals are intuitive and require no access to model internals, only the ability to query it. They align well with fairness and recourse concerns and with regulations that require meaningful explanation of automated decisions, because they translate directly into steps a person can take. They also expose model weaknesses when the required change is trivial or nonsensical.

Cautions

A counterfactual describes the model decision boundary, not necessarily a real causal path; acting on a spurious feature may satisfy the model without changing the true outcome. Multiple valid counterfactuals can exist, and offering an unstable or unrealistic one is worse than none. Counterfactuals sit alongside SHAP and LIME in the interpretability toolkit, emphasizing recourse over attribution.