What is an AI counterfactual explanation?

A counterfactual explanation explains a model's decision as "had this feature been so, the outcome would differ", showing the smallest input change that would alter the result; for example, your application would have been approved with a certain higher annual income.

Unlike algorithmic recourse, which suggests only actions a person can really take, a counterfactual finds any outcome-changing change, possibly an unchangeable trait such as age. Feature attribution scores each feature's contribution but does not say what change would flip the outcome.

Topic
Responsible AI and governance
Also known as
Counterfactual
Origin
2017

How an AI counterfactual explanation works

  1. The decision to explain and the desired different outcome, such as approval instead of refusal, are set.
  2. A new input closest to the original that gives the desired result is sought; closeness is measured by number and size of changes.
  3. The search is bounded by realistic value ranges, with unchangeable features held fixed.
  4. The differences found are presented in plain language to the person or expert; several options can be shown.

In more detail

Causal constraints and plausibility on the data manifold

Real-world features are rarely independent: increasing years of education or income often implies changes in age, tenure or tax bracket. Without enforcing causal relationships or data-manifold plausibility constraints, a counterfactual generator can recommend impossible combinations or push points into sparse out-of-distribution regions where the model's predictions are unreliable.

Multiple solutions, diversity and robustness

High-stakes decisions often yield multiple valid counterfactuals (the Rashomon effect), creating a consistency challenge: similar applicants may receive conflicting advice or a tiny update to the model may invalidate previously given guidance ("recourse invalidation"). Production systems address this by generating a small, diverse set of robust counterfactuals that remain valid under minor model updates.

The objective function: balancing proximity, sparsity and diversity

Modern counterfactual libraries (such as DiCE) optimise a joint objective balancing proximity (small L1/L2 or mixed-type distance), sparsity (few changed features), plausibility and diversity across alternatives, using either gradient-based solvers for differentiable models or model-agnostic genetic/nearest-unlike-neighbour search for tree ensembles and APIs.

Commonly confused terms

TermHow it differs
Algorithmic recourseAlgorithmic recourse is a subset/extension of counterfactual explanations that restricts suggested changes strictly to feasible, actionable steps a person can realistically perform (excluding immutable traits like age or impossible jumps).
Feature attributionFeature attribution (e.g., SHAP, LIME) scores how much each input feature contributed to the current prediction, whereas counterfactual explanations show the minimal input changes required to flip the decision to a different outcome.
Adversarial exampleAdversarial examples also seek the smallest input perturbation that flips a model's prediction, but typically target imperceptible or out-of-distribution changes to fool the model, whereas counterfactual explanations seek meaningful, human-interpretable, in-distribution changes.

Why an AI counterfactual explanation matters for on-premises AI

As they can be generated from inputs and outputs alone, counterfactuals work for black-box models and trade-secret systems; the paper proposing them frames them as explaining automated decisions without opening the black box. They are understandable, giving a concrete what-would-change answer rather than a rationale. Limits: many may exist, some unrealistic or involving unchangeable traits, so generation is constrained and results reviewed.

ON-PREMISES EXAMPLE

A leasing company gives customers with refused applications counterfactual explanations showing under which condition the decision would change; age and marital status stay fixed, with only changeable terms such as down payment and term appearing.

Common questions

How does a counterfactual explanation differ from algorithmic recourse?

A counterfactual finds the smallest outcome-changing change. Recourse picks from these only actions the person can really take.

Does a counterfactual explanation need the model's internals?

No. It can be generated from the model's inputs and outputs alone, so it works for black-box models too.

Sources

In the glossary: Glossary, A to D

What does this term mean for your infrastructure?

We can work out together in a technical assessment how it maps onto your data, hardware and security requirements.

Request a technical assessment →

This site sets no cookies. Visitor numbers are counted in aggregate using a cookieless method that does not identify anyone. See the Privacy Policy for details.