A contrastive explanation is an account of a model decision that answers the question “why P rather than Q?”, where P is the actual output, called the fact, and Q is a specific alternative, called the foil. In explainable AI, it identifies the features or evidence that distinguish the observed prediction from the foil, instead of listing every factor that contributed to the prediction in general.
The approach rests on a well-established finding from philosophy and cognitive science: people rarely ask why something happened in absolute terms, but why it happened instead of something else. A loan applicant does not want a ranked list of all 40 model inputs; the applicant wants to know what separated a rejection from an approval. Contrastive methods therefore tend to produce shorter, more selective explanations that match how humans reason about causes.
How contrastive explanations work
Every contrastive explanation starts by fixing a fact and a foil. The foil may be chosen by the user, such as an alternative class in a classifier, or inferred automatically, typically as the second most likely class or the decision that a user expected. The explanation then reports the difference condition: the attributes present for the fact and absent for the foil, or vice versa.
Technically, most methods solve a constrained optimization problem. They search for the smallest change to the input, or the smallest subset of evidence, that would flip the output from the fact to the foil. The size of that change is measured with a distance function, often the L1 norm to encourage sparse answers that involve only a few features.
The table below lists the components that any contrastive method must define, explicitly or implicitly.
| Component | Meaning | Typical choice |
|---|---|---|
| Fact | The output the model actually produced | Predicted class or score |
| Foil | The alternative the explanation contrasts against | User-chosen or second-ranked class |
| Difference condition | Evidence that separates fact from foil | Small set of features or regions |
| Distance measure | How large a change is considered | L1 or L2 norm, feature costs |
| Constraints | Rules on allowed changes | Plausibility, immutable features |
Main methods and variants
Several families of techniques produce contrastive explanations, and they differ in what they return. Counterfactual explanations describe a modified input that leads to the foil, while the Contrastive Explanations Method (CEM) returns pertinent positives that must be present to keep the fact and pertinent negatives whose absence matters for it.
| Method family | Output | Typical data |
|---|---|---|
| Counterfactual search | Nearest input that receives the foil | Tabular decisions such as credit |
| Diverse counterfactuals | Several distinct paths to the foil | Recourse for individuals |
| Contrastive Explanations Method | Pertinent positives and negatives | Images and tabular data |
| Contrastive saliency maps | Regions supporting fact over foil | Image classifiers |
| Contrastive text explanations | Tokens that favor one label | Language models and classifiers |
Gradient-based variants compute attribution for the difference between two logits rather than for a single class score. This simple change turns a standard saliency map into a contrastive one, highlighting what makes an image look like a husky rather than a wolf instead of what makes it look like a dog at all.
Contrastive explanation compared with related approaches
Contrastive explanation is a framing of the question, not a single algorithm, so it overlaps with neighboring explanation types. Feature attribution methods such as Shapley values explain a prediction relative to a baseline or average, which is an implicit foil that users rarely notice.
| Explanation type | Question answered | Implicit reference point |
|---|---|---|
| Contrastive explanation | Why P rather than Q | Explicit foil Q |
| Feature attribution | How much each feature contributed | Baseline or average prediction |
| Counterfactual explanation | What change would alter the outcome | Desired outcome |
| Example-based explanation | Which cases resemble this one | Training examples |
| Global explanation | How the model behaves overall | Whole data distribution |
Counterfactual explanations are best seen as a subset of contrastive explanations in which the foil is a desired outcome. Making the foil explicit also exposes a weakness of attribution methods: changing the baseline can change the explanation substantially, which a contrastive formulation states openly.
Practical use and design choices
Contrastive explanations are most valuable where a person must act on or contest a decision. Credit, insurance, hiring and medical triage are typical cases, and adverse action notices in lending already require lenders to state the principal reasons for a denial, which naturally takes a contrastive form.
- Choose the foil deliberately: the expected or desired outcome is usually more useful than the runner-up class.
- Mark immutable features such as age or birthplace so that explanations do not suggest impossible changes.
- Assign feature costs so that suggested changes reflect real effort, not only numerical distance.
- Keep explanations sparse, typically two to four features, because longer answers lose the contrastive benefit.
Limitations and risks
The quality of a contrastive explanation depends heavily on the foil and the constraints, and poor choices produce answers that are technically correct but useless or misleading. Because many models fit the same data equally well, the Rashomon effect also means that different models may justify the same decision with different contrasts.
| Problem | Cause | Mitigation |
|---|---|---|
| Implausible suggestions | Search leaves the data manifold | Add density or plausibility constraints |
| Unactionable advice | Immutable features allowed to change | Freeze protected and fixed attributes |
| Unstable explanations | Small input changes alter the result | Test robustness across neighbors |
| Unfaithful contrast | Approximation differs from the model | Verify that the foil is truly reached |
| Model extraction risk | Many counterfactuals reveal boundaries | Limit queries and detail per user |
Contrastive explanations also do not establish causality in the real world. They describe what flips the model, not what would change the underlying outcome, and treating them as causal guidance can lead people to game proxy features without improving the property the model was meant to measure.
Understanding it simply
People rarely ask why something happened in general. They ask why it happened instead of something else. Why did the train leave late and not on time? Why was the loan refused and not approved?
A contrastive explanation answers that kind of question for a computer model. It points to the few differences that mattered. A short answer such as “your income was slightly too low for approval” is far more useful than a long list of every factor the system considered.
Applied in practice
A regional bank uses a gradient boosting model to screen small business loans. An applicant with annual revenue of 180,000 dollars and a debt-to-income ratio of 46 percent is refused. The bank’s explanation service sets the foil to approval and searches for the smallest realistic change, with company age and industry marked as immutable.
The service returns two contrasts: reducing the debt-to-income ratio to 38 percent, or adding six more months of positive cash flow history. The loan officer shares the first option in the denial notice. Eight months later, the applicant pays down a credit line, reapplies and is approved, and the bank records the case as successful recourse in its fairness monitoring report.