TAI BUI
Back to curriculum
LearnPython

Fairness Criteria — Group, Individual, Counterfactual

Fairness has three families, and they define the standard differently. Group fairness asks for equal rates across protected groups on average: demographic parity, equalized odds, conditional use accuracy equality. Individual fairness (Dwork et al. 2012) asks that similar individuals get similar decisions, formalized as a Lipschitz condition on the decision map. Counterfactual fairness (Kusner et al. 2017) asks that a decision stay the same when the person's sensitive attributes are counterfactually altered. Recent work adds three twists. A NeurIPS 2024 result shows an inherent trade-off between counterfactual fairness and accuracy, along with a model-agnostic way to convert an optimal-but-unfair predictor into a counterfactually fair one at bounded accuracy cost. Backtracking counterfactuals (arXiv:2401.13935, January 2024) avoid intervening on legally protected attributes. And an ICLR Blogposts 2024 piece argues that, given a causal graph, satisfying certain group fairness measures entails counterfactual fairness.

TIME: ~60 minutesPREREQUISITES: Phase 18 · 20 (bias), Phase 02 (classical ML)

Learning Objectives

  • State the three group-fairness criteria (demographic parity, equalized odds, conditional use accuracy equality) and one impossibility result.
  • Describe individual fairness via the Dwork et al. 2012 Lipschitz formulation.
  • Describe counterfactual fairness and its causal-graph dependency.
  • Explain backtracking counterfactuals and why they sidestep the intervention-on-protected-attribute problem.

The Problem

Lesson 20 was about measuring bias. This lesson is about defining the fairness standard that measurement should serve. The three families set structurally different standards, so a model can be group-fair and individual-unfair, or counterfactually fair and group-unfair. Choosing a standard is a policy decision.

Warm-up0/3
1. A classifier is evaluated on a labeled test set. Which quantity is the true-positive rate (TPR)?Warm-up
A confusion matrix with actual-positive and actual-negative rows against predicted-positive and predicted-negative columns, filled with illustrative counts, and a dashed box asking for TPR.
Illustrative numbers, not from the lesson.
2. Group A has 30% truly positive examples and group B has 60%. What is that difference called?Warm-up
A bar chart of two groups' share of truly positive examples, 30 percent for group A and 60 percent for group B, with a question asking what that difference between the groups is called.
Numbers as given in the stem.
3. A model predicts 'positive' for 40 people, and 30 of those 40 truly are positive. What is the model's precision on this set?Warm-up
Forty dots representing people predicted positive, thirty colored as truly positive and ten colored as truly negative, with a dashed box asking for the model's precision.
Numbers as given in the stem.
Check: The Problem0/2
1. Why can one model be group-fair and individual-unfair, or counterfactually fair and group-unfair?Explain
A box reporting the same model passes a group-fairness audit and a second box reporting the same model fails an individual-fairness audit, with a dashed box asking why this can happen.
Both audits run on the same trained model, as given in the stem.
2. A hospital's committee cannot agree whether its triage model should equalize acceptance rates or equalize predictive value across groups, and base rates differ. What is the right first step?Design
A box for one option the committee favors, equalizing acceptance rates, and a box for another option, equalizing predictive value, with a dashed box asking the right first step, given the groups' base rates differ.
The two groups' base rates differ, as given in the stem.

The Concept

Group fairness

  • Demographic parity. P(Y=1 | A=a) = P(Y=1 | A=a') for all groups. Equal acceptance rates.
  • Equalized odds. P(Y=1 | Y*=y, A=a) = P(Y=1 | Y*=y, A=a'). Equal TPR and FPR across groups.
  • Conditional use accuracy equality. P(Y*=y | Y=y, A=a) = P(Y*=y | Y=y, A=a'). Equal predictive value across groups.

Impossibility (Chouldechova, Kleinberg-Mullainathan-Raghavan 2017): when base rates differ across groups, these three cannot be satisfied simultaneously.

Individual fairness

Dwork et al. 2012. A decision map f is individually fair with respect to a task-specific similarity metric d if |f(x) - f(x')| <= L * d(x, x') for some Lipschitz constant L. Similar individuals get similar decisions.

You have to define d, and that is a policy question, not a statistical one.

Counterfactual fairness

Kusner et al. 2017. A decision is counterfactually fair to individual i if, under a causal model of the population, the decision is unchanged when i's sensitive attributes are counterfactually altered.

This needs a causal DAG, and the DAG is a modeling choice. Counterfactual fairness is only as justified as the DAG behind it.

The CF-vs-accuracy trade-off

A 2024 NeurIPS theory result says counterfactual fairness and predictive accuracy trade off against each other. A model-agnostic method can convert an optimal-but-unfair predictor into a CF one at a bounded accuracy cost, and that cost depends on the magnitude of the sensitive-attribute coefficient in the optimal unfair predictor.

Backtracking counterfactuals

arXiv:2401.13935 (January 2024). Traditional counterfactuals intervene on the sensitive attribute: "would the decision change if this person had been a different gender?" That is legally problematic, because classification law does not allow interventions on protected attributes.

Backtracking counterfactuals flip the direction. Instead of intervening on the attribute, you ask what combination of the individual's actual features would have produced the counterfactual outcome. That sidesteps the legal objection.

Philosophical reconciliation

ICLR Blogposts 2024. With a causal graph in hand, satisfying certain group-fairness measures entails counterfactual fairness. So the three families are not orthogonal. They look like different facets of one underlying causal structure.

This does not resolve the impossibility theorems, since unequal base rates still block simultaneous group fairness. What it shows is that the apparent opposition between "group" and "individual / counterfactual" is partly an artifact of leaving the causal model implicit.

Where this fits in Phase 18

Lesson 20 covers bias measurement and this one covers fairness definition. Lesson 22 is privacy (differential privacy) and Lesson 23 is watermarking. Together they are the allocation-adjacent lessons that complement the deception-adjacent Lessons 7-11.

Check: The Concept0/22
1. What does demographic parity require of a classifier across groups?Define
Two bars showing each group's rate of positive decisions, with a dashed box asking what demographic parity requires of these two numbers.
Illustrative numbers, not from the lesson.
2. Which group-fairness criterion requires equal true-positive and false-positive rates across groups?Define
Two side-by-side bar charts, one for each group's true-positive rate and one for each group's false-positive rate, with a dashed box asking for the name of the criterion that requires these to match across groups.
Illustrative numbers, not from the lesson. Both conditioned on the true label.
3. Which group-fairness criterion requires equal predictive value (equal PPV and NPV) across groups?Define
Two side-by-side bar charts, one for each group's positive predictive value and one for each group's negative predictive value, with a dashed box asking for the name of the criterion that requires these to match across groups.
Illustrative numbers, not from the lesson. Both conditioned on the model's decision.
4. What does individual fairness, in the Dwork et al. formulation, require?Define
Two applicant boxes labeled Person P and Person P prime, noted as close to each other under a task-specific closeness measure, with a dashed box asking what must hold about their decisions.
A task-specific closeness, not necessarily a raw feature match.
5. What does counterfactual fairness require of a decision?Define
Two boxes for the same individual, an actual world with attribute a and decision D, and a counterfactual world with the attribute changed to a prime and the decision left as a question mark, both under the same causal model.
Both evaluated under the same causal model of the population.
6. What is a backtracking counterfactual?Define
A box for an actual loan case with a decision of rejected, next to a box posing a counterfactual query about the attribute, with a dashed box asking what reasoning direction a backtracking counterfactual uses.
The direction of reasoning used to answer the query is not shown here.
7. What does the Chouldechova / Kleinberg-Mullainathan-Raghavan impossibility result say?Define
The names of the three group-fairness criteria, with the fact that the two groups' base rates differ, and a dashed box asking what follows for the three criteria together.
Numbers as given in the stem.
8. How does equalized odds differ from conditional use accuracy equality?Explain
A table of predicted decision against true label with the cells left blank, and a dashed box asking which of equalized odds and conditional use accuracy equality fixes which side of the table.
Both criteria read the same table of decision versus true label.
9. Why is demographic parity a hard target to hit when two groups have different base rates?Explain
A bar chart of two groups' share of truly positive examples, 30 percent and 60 percent, with a dashed box asking why demographic parity is hard to hit given this gap.
Base rates as used throughout this lesson's running example.
10. Why does individual fairness require defining the similarity metric d, and why is that hard to settle statistically?Explain
The Lipschitz inequality written out symbolically, with the similarity metric d noted as something that must be chosen before the check can run, and a dashed box asking why data alone cannot pick it.
d is a similarity metric that must be chosen before this check can run.
11. Why is counterfactual fairness 'only as justified as the DAG behind it'?Explain
A simple causal graph with nodes A, X and Y connected by arrows, captioned as one analyst's modeling choice, with a dashed box asking what happens if a different analyst draws a different graph.
One analyst's causal graph; the lesson calls choosing it a modeling choice.
12. In the 2024 trade-off result for counterfactual fairness and accuracy, what determines the accuracy cost of converting an optimal-but-unfair predictor into a counterfactually fair one?Explain
A box for an optimal-but-unfair predictor trained to maximize accuracy, converted into a counterfactually fair predictor at some bounded accuracy cost, with a dashed box asking what sets the size of that cost.
The conversion method is model-agnostic, as given in the stem.
13. Why is intervening on a protected attribute a problem for traditional counterfactual fairness in a legal setting?Explain
A box with attribute set to female and an arrow labeled intervene leading to a box with the attribute changed to male, with a dashed box asking why this step is risky under classification law.
This is the step a traditional counterfactual fairness check takes.
14. How do backtracking counterfactuals sidestep that legal objection?Explain
A single box stating that directly changing the attribute is legally risky, with a dashed box asking what an alternative approach must avoid doing.
Restates the legal problem traditional counterfactuals run into.
15. What does the philosophical reconciliation of group and counterfactual fairness claim?Explain
A causal graph box above three separate boxes for group fairness, individual fairness and counterfactual fairness with no lines drawn between them, and a question asking how the three relate given the graph.
No relation between the three boxes is drawn here.
16. Group B has 50 truly positive and 50 truly negative people. The model flags 30 of the positives and 10 of the negatives. What are group B's TPR and FPR?Apply
A confusion matrix for group B with 30 of 50 actual positives predicted positive and 10 of 50 actual negatives predicted positive, with a dashed box asking for TPR and FPR.
Numbers as given in the stem.
17. A map has f(x) = 0.9 and f(x') = 0.5 for two people with d(x, x') = 0.3. Using L = 1, is the Lipschitz condition met?Apply
Two decision values, 0.9 and 0.5, a distance of 0.3 between the people, and the Lipschitz inequality with L equal to 1, with a dashed box asking whether the pair satisfies it.
Numbers as given in the stem.
18. A model approves 20 of 100 applicants in group A and 40 of 100 in group B. Which criterion's gap does this directly show, and how large is it?Apply
A bar chart of approvals out of 100 for group A and group B, 20 and 40, with no true outcomes mentioned, and a question asking which criterion's gap this shows and how large it is.
Numbers as given in the stem. No true outcomes are mentioned for either group.
19. A lender audits a loan model and finds equal approval rates for two groups with different repayment rates. A regulator then asks whether approved applicants in each group repay at the same rate. What is the right reading?Analyze
A bar chart showing equal approval rates for two groups next to a box noting their repayment rates differ, with a dashed box asking for the right reading of both facts together.
Both facts as stated in the stem.
20. Two teams both audit the same hiring model for counterfactual fairness and reach opposite verdicts. What is the most likely source of the disagreement?Analyze
A box reporting team one's audit of a hiring model finds it counterfactually fair and a second box reporting team two's audit of the same model finds it not fair, with a dashed box asking the likely source of the disagreement.
Both teams audit the same trained model, as given in the stem.
21. A team claims its model is individually fair with L = 1. Their similarity metric d ignores most of the features that a domain expert thinks matter for the task. What is the problem?Analyze
A box noting the team's similarity metric d uses only one feature, next to a box noting a domain expert considers several more features relevant, with a dashed box asking the problem with this check.
Both facts as given in the stem.
22. You must audit a credit model where law forbids hypothetical interventions on a protected attribute, but you still want a counterfactual-style test. Which approach fits?Design
A box stating the audit may not intervene on the protected attribute, next to a box stating the goal is still some counterfactual-style test, with a dashed box asking which approach fits.
Both facts as given in the stem.

Use It

code/main.py builds a toy binary-classification dataset with a sensitive attribute and unequal base rates. It trains a simple classifier and computes demographic parity, equalized odds, and conditional use accuracy equality, so you can watch the three metrics disagree. Then it applies a re-weighting aimed at demographic parity, and you can see what that does to the other two.

Check: Use It0/4
1. In main.py the sensitive attribute a is placed in the feature vector as [x0, x1, float(a)]. What follows for the trained logistic classifier?Apply
The feature vector x equals x0, x1, a and the formula z equals b plus w0 times x0 plus w1 times x1 plus w2 times a, with a dashed box asking whether the classifier uses a.
Structure as given in the stem; weight values are not shown here.
2. In main.py the demographic-parity re-weighting assigns weight 2.0 to group-0 positives and 0.5 to group-1 positives. Which weight do the group-0 negative examples get?Apply
A table of weight by group and label with group-0 positive given as 2.0 and group-1 positive given as 0.5, and the two negative-label cells left as question marks, with a dashed box asking for the group-0 negative weight.
The two y=1 weights are given in the stem; the y=0 weights are not.
3. On the same test set, main.py reports demographic parity, TPR and FPR, and PPV and NPV for each group. After the demographic-parity re-weighting, what does it show?Apply
A list of the five metrics main.py reports per group, demographic parity, TPR, FPR, PPV and NPV, noted as printed both before and after the re-weighting step.
These five quantities are reported both before and after the re-weighting step.
4. A team re-weights training data until the acceptance rates for two groups match, and then reports 'the model is fair'. Their groups have unequal base rates. What is the main flaw in that conclusion?Analyze
A bar chart of two groups' acceptance rates now matched by re-weighting, next to a box stating the team's claim that the model is fair, with a dashed box asking the main flaw in that conclusion, given the groups have unequal base rates.
Groups have unequal base rates, as given in the stem.

Ship It

This lesson produces outputs/skill-fairness-criterion.md. Given a fairness claim or policy, the skill identifies which criterion is being claimed, whether the model can satisfy the other criteria under the stated unequal base rates, and which causal DAG the claim depends on.

Check: Ship It0/1
1. A vendor says its hiring screen is 'fair'. You are asked to review the claim. Which review plan uses the lesson's ideas?Design
A box with a vendor's claim that its hiring screen is fair, next to a box noting the task is to design a review plan, with a dashed box asking what that plan should include.
Both facts as given in the stem.
Author's Note

I'd run main.py first and read the printed gaps before the definitions. The data generator sets the base rate to 0.3 for group 0 and 0.6 for group 1, and a plain logistic classifier trained on it reports demographic parity, equalized odds (TPR and FPR), and conditional use (PPV and NPV) side by side. Seeing all five numbers per group makes the three criteria feel like three different questions about the same predictions.

Pay attention to what the re-weighting does. It scales the loss on positive examples, by 2.0 for group 0 and 0.5 for group 1, and nothing else changes. With the fixed seed, the demographic-parity gap shrinks while the PPV and NPV gaps between the groups get wider. That is the impossibility result at small scale, and I find it more convincing than the statement of the theorem.

Keep the scope of the code in mind. It implements only the group criteria. Individual fairness and counterfactual fairness have no code here, and both depend on choices the toy never makes: a similarity metric d for one, a causal DAG for the other. The sensitive attribute is also passed to the classifier as its third feature, so this model is not blind to it. Exercise 2 is where I'd start if you want to feel the individual-fairness side, because defining d forces the policy question the Concept section talks about.

Exercises

  1. Run code/main.py. Report the three group metrics on the default data. Apply the demographic-parity-targeted re-weighting and re-report.

  2. Implement the Dwork et al. 2012 individual-fairness metric using L2 on non-sensitive features. Report how many pairs violate Lipschitz with constant L=1.

  3. Read Kusner et al. 2017. Construct a simple two-feature causal DAG for resume scoring and identify the counterfactual-fairness condition it implies.

  4. The 2024 backtracking-counterfactuals paper avoids intervention on protected attributes. Describe a scenario where this matters for legal compliance.

  5. The ICLR 2024 reconciliation argues group and counterfactual fairness are facets of the same structure. Pick two of the three criteria in code/main.py and state the causal assumption that would make them equivalent.

Key Terms

TermWhat people sayWhat it actually means
Demographic parity"equal rates"P(Y=1
Equalized odds"equal TPR/FPR"Equal true-positive and false-positive rates across groups
Conditional use accuracy"equal PPV/NPV"Equal predictive values across groups
Individual fairness"Lipschitz condition"Similar individuals get similar decisions
Counterfactual fairness"causal alteration invariance"Decision unchanged under counterfactual attribute alteration
Backtracking counterfactual"explain via actuals"Counterfactual reasoned backward from outcome, not forward from attribute
Impossibility theorem"the three conflict"Chouldechova / KMR 2017: group criteria mutually exclusive under unequal base rates

Further Reading

Code

Ships With