Foundations to Frontier
Tests
P. Responsible AI › P Responsible AI

Fairness: Definitions, Metrics, Mitigation

A model is used fairly when its errors and benefits do not fall unjustly on some groups of people. Group fairness turns this into measurable criteria: equal selection rates (demographic parity), equal true positive rates (equal opportunity), equal true and false positive rates (equalised odds), equal precision (predictive parity) and calibration within each group. When groups have different base rates these criteria conflict, and no classifier short of a perfect one meets them all. The exercises compute the metrics and then apply three policies to a perfectly calibrated score in two groups with base rates 0.3 and 0.5: one threshold leaves a selection gap of 0.41 and a true positive rate gap of 0.45; group thresholds close either gap at a cost of 1 to 2 points of accuracy while opening a precision gap of 0.18 to 0.21. Practice problems cover Chouldechova's identity, fairness through unawareness, the noise in small-group audits, biased labels, and the accuracy cost of a fairness constraint.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Who bears the errors

Models that screen loan applicants, flag patients or rank job candidates make mistakes, and those mistakes can fall more heavily on some groups than others. Fairness metrics make the differences visible: who is selected, whose true cases are missed, who is wrongly flagged. They also show that some reasonable goals cannot all hold at once, so choosing among them is a decision about values and context.

🎮 Responsible AI lab

100,000 people; the risk score is perfectly calibrated, but group 1 has a base rate of 0.5 and group 0 of 0.3. Pick a decision policy:

accuracy 68.2%
gap in selection rate
0.410
gap in true positive rate
0.448
gap in false positive rate
0.328
gap in precision (PPV)
0.049

When base rates differ, closing one gap opens another: which one matters is a decision about the application, not a technical default.

Why engineers care

In Exercise 2, a perfectly calibrated score with one threshold left a true positive rate gap of 0.448 between groups; equalising it cost 1.1 points of accuracy and opened a precision gap of 0.178.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Demographic parity asks for equal…
  2. 2. Equal opportunity asks for equal…
  3. 3. When groups have different base rates, the common fairness criteria…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Selection rate: share predicted positive. Demographic parity: equal selection rates across groups.
  • Equal opportunity (M. Hardt, E. Price and N. Srebro, 2016): equal true positive rates. Equalised odds: equal true and false positive rates.
  • Predictive parity: equal positive predictive value (precision). Calibration within groups: among people given score s, a share s are positive, in every group.
  • Impossibility: with different base rates, calibration and equal error rates cannot both hold unless prediction is perfect (A. Chouldechova, 2017; J. Kleinberg, S. Mullainathan and M. Raghavan, 2016).
  • Mitigation: before training (reweighing, collecting better data), during training (constraints or penalties) or after (group-specific thresholds).
  • Beyond metrics: biased labels, proxies for protected attributes, small groups with noisy estimates, and whether the decision should be automated at all.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Equalised odds requires equal…
  2. 2. A score is calibrated within groups if…
  3. 3. Group-specific thresholds are a form of…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

Measuring and trading off fairness

Exercise 1.

  • For each group compute the selection rate, true and false positive rates and precision.
  • Report the largest difference between groups for each.
  • Check calibration within each group with the expected calibration error.

Practice.

  • Choose the criterion from the harm: missed positives (equal opportunity) or false accusations (false positive rate), and state it.
  • Report every gap and the base rates, not one favourable metric.
  • Check labels for bias before trusting any metric computed from them.
  • Put confidence intervals on group metrics, especially for small groups.
  • Removing the protected attribute is not enough when proxies remain.
def rates(y, yhat):
    y, d = y.astype(bool), yhat.astype(bool)
    return dict(selection=d.mean(), tpr=d[y].mean(), fpr=d[~y].mean(), ppv=y[d].mean())
t0 = threshold_for(s[g == 0], tpr, "tpr", y[g == 0])   # same TPR in both groups
t1 = threshold_for(s[g == 1], tpr, "tpr", y[g == 1])
d = apply(s, g, (t0, t1)); print(gaps(y, d, g))
🐍 Exercise 1: group fairness metrics
Compute selection rates, true and false positive rates, precision and within-group calibration, and the gaps between groups.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Dropping the group attribute but keeping a proxy left a selection gap of about…
  2. 2. An audit of a group with 50 positives showed a TPR gap of 0.05 or more, when the true gap was 0, in about…
  3. 3. A score learned from labels missing 30% of group 1's positives selected…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Chouldechova’s identity. In a group with base rate p, the counts give FP = TP × (1 − PPV)/PPV, TP = TPR × P and N = P(1 − p)/p, so FPR = FP/N = (p/(1 − p)) × ((1 − PPV)/PPV) × TPR. If two groups have the same PPV and TPR but different p, their FPRs must differ.

Calibration and balance. If a score is calibrated in a group, the mean score of its positives and of its negatives are tied to the base rate; Kleinberg, Mullainathan and Raghavan showed that equal means for positives and for negatives across groups then require equal base rates or perfect prediction.

The best unconstrained threshold. With a calibrated score s, predicting positive gains accuracy when s exceeds 0.5, so one threshold of 0.5 maximises accuracy, and any fairness constraint can only lower it or leave it unchanged.

Noise in audits. A group’s TPR estimated from n positives has standard error about the square root of TPR(1 − TPR)/n. For TPR = 0.7 and n = 200 that is 0.032, so a gap of 0.05 appears by chance about 12% of the time even when the true gap is 0.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Chouldechova's identity links FPR to…
  2. 2. With a calibrated score, the accuracy-maximising threshold is…
  3. 3. The standard error of a TPR estimated from n positives shrinks like…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

When groups have different base rates, what does each fairness policy cost and which gaps does it leave?

History.

  • US employment law’s four-fifths rule (1978) flagged selection rates below 80% of the highest group’s as evidence of adverse impact.
  • J. Angwin and colleagues at ProPublica (2016) reported that the COMPAS recidivism score had a higher false positive rate for Black defendants; its makers replied that it was equally well calibrated across groups.
  • A. Chouldechova (2017) and J. Kleinberg, S. Mullainathan and M. Raghavan (2016) proved that both claims could be true at once, and that both properties cannot hold when base rates differ.
  • M. Hardt, E. Price and N. Srebro (2016) defined equal opportunity and equalised odds and showed how to achieve them with group thresholds; J. Buolamwini and T. Gebru (2018) found error rates of commercial face analysis up to 34.7% for darker-skinned women against 0.8% for lighter-skinned men.

Exercise 2.

  • 100,000 people: group 0 (70%) with true probabilities from Beta(3, 7) (mean 0.3), group 1 (30%) from Beta(5, 5) (mean 0.5). The score is the true probability, so it is perfectly calibrated.
  • Policies: one threshold of 0.5; group thresholds giving both groups the overall selection rate (demographic parity); group thresholds giving both groups the overall true positive rate (equal opportunity).

Seed 0:

policy accuracy selection gap TPR gap FPR gap PPV gap
one threshold of 0.5 68.2% 0.410 0.448 0.328 0.049
demographic parity 66.7% 0.000 0.058 0.023 0.193
equal opportunity 67.1% 0.046 0.000 0.012 0.178

Seeds 1 and 2: accuracy 68.5% and 68.7% with one threshold, 66.5% and 66.9% with demographic parity, 66.8% and 67.2% with equal opportunity; PPV gaps 0.061 and 0.057, 0.211 and 0.209, 0.200 and 0.194.

Findings.

  • One threshold on a calibrated score kept precision nearly equal (gap about 0.05 to 0.06) but selected group 1 far more often and gave it a TPR 0.45 higher and an FPR about 0.32 higher.
  • Group thresholds closed the targeted gap at a cost of 1.1 to 2.1 points of accuracy.
  • They opened a precision gap of 0.18 to 0.21: a positive decision meant something different in each group.
  • The choice among criteria cannot be made by the data; it depends on what errors cost and to whom.
🐍 Exercise 2 (research): when groups have different base rates, what does each fairness policy cost and which gaps does it leave?
Apply one threshold, demographic-parity thresholds and equal-opportunity thresholds to a calibrated score in two groups with different base rates, and measure accuracy and every fairness gap.

Fairness in practice

  • Start from the decision: who is affected, what each error costs them, and whether a model should make it.
  • Audit by group with every metric, base rates and confidence intervals, including intersections of groups (topic P-5).
  • Investigate labels and features: historical decisions, under-recording, and proxies for protected attributes.
  • Mitigate and re-measure: better data first, then constraints or thresholds; document the trade-off chosen.
  • Check the law: anti-discrimination rules may forbid using a protected attribute directly even to correct bias (topic P-6).

References

  1. M. Hardt, E. Price and N. Srebro (2016). “Equality of opportunity in supervised learning.” NeurIPS.
  2. A. Chouldechova (2017). “Fair prediction with disparate impact: a study of bias in recidivism prediction instruments.” Big Data.
  3. J. Kleinberg, S. Mullainathan and M. Raghavan (2017). “Inherent trade-offs in the fair determination of risk scores.” ITCS.
  4. J. Buolamwini and T. Gebru (2018). “Gender shades: intersectional accuracy disparities in commercial gender classification.” FAccT.
  5. S. Barocas, M. Hardt and A. Narayanan (2023). Fairness and Machine Learning: Limitations and Opportunities. MIT Press.