Ethical AI · Advanced level

Advanced level · Module 4: Explainable AI Techniques and Interpretability · Lesson 3 of 4

Counterfactual Explanations

Learners create counterfactual explanations ('what would need to change for a different outcome?') and judge whether the suggested changes are actionable and fair.

In this lesson you will

  • Generate counterfactual explanations for individual cases
  • Assess whether counterfactuals are actionable and fair

Key concepts

counterfactual explanationactionabilityimmutable featuresplausibilityrecourse

The lesson

A counterfactual explanation states the smallest realistic change that would alter a decision: 'If attendance had been above 85%, the student would have been predicted to pass.' It gives people recourse, meaning something they can act on.

Counterfactuals must respect reality. Some features cannot or should not be changed (age, gender, county of origin), and some changes are implausible. A counterfactual that says 'move to Juba' is not fair recourse.

A simple search method changes actionable features in small steps and records the first change that flips the prediction. The What-If Tool offers a visual way to explore this for some models. Always present counterfactuals as describing the model, not as advice that guarantees an outcome.

Step by step

  1. List actionable and immutable features for the capstone system.
  2. Write a function that searches small changes to actionable features until the prediction flips.
  3. Generate counterfactuals for five cases.
  4. Review each for plausibility and fairness.

Practice activity

Generate and review counterfactual explanations for five capstone cases.

Expected result: Five plausible, actionable counterfactuals with a fairness review of each.

Check your understanding

  1. What is recourse?

    Show answer

    A realistic action a person could take to obtain a different decision.

  2. Why exclude features like gender from counterfactual changes?

    Show answer

    They are immutable or should not be changed, so they offer no fair recourse.

Further learning

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.