Simple Algorithm
Artificial Intelligence · Hidden Layer · 22 min

Bias & Fairness

Where bias comes from and how fairness is defined.

A lender sets the most accurate thresholds it can find and ends up approving 54% of one group and 19.5% of the other. Equalizing the approval rates fixes that gap and leaves the error rates far apart. This lesson makes "fair" precise: where bias enters a pipeline, the three families of group criteria and a proof that two of them clash, what each criterion costs in accuracy, and fairness for individuals rather than groups.

What you’ll learn

  • Trace bias to its sources in the machine-learning pipeline, including biased labels and feedback loops, and explain why dropping the sensitive attribute fails.
  • State independence, separation and sufficiency as conditional-independence conditions, with demographic parity, equalized odds, equal opportunity, calibration and predictive parity as instances.
  • Prove that demographic parity and equalized odds cannot both hold when base rates differ, unless the classifier is uninformative.
  • Derive accuracy-optimal group thresholds, and measure what each fairness criterion costs in the widget.
  • State Dwork et al.'s individual fairness, and prove that it bounds group disparities by an earthmover distance.

Where bias enters

Algorithmic bias is rarely a single bug. Suresh & Guttag (2021) trace harms to seven stages of the machine-learning life cycle:

  • Historical bias: the world the data record was itself unequal, as with past hiring decisions.
  • Representation bias: some groups are scarce in the data, as in the face datasets behind the Gender Shades audit.
  • Measurement bias: a label or feature is a proxy that works differently across groups, such as arrests standing in for crime.
  • Aggregation bias: one model is fit to groups whose features relate to the outcome differently.
  • Learning bias: the objective trades a small group's accuracy for a large group's, as minimizing average loss does.
  • Evaluation bias: the benchmark does not represent the population the model will serve.
  • Deployment bias: the system is used differently from its design, for instance as a decision rather than a decision aid.

Two more mechanisms defeat naive fixes. Proxies: deleting the sensitive attribute AA from the inputs, fairness through unawareness, leaves every feature correlated with it. The best predictor from the remaining features XX is E[Y∣X]=∑aE[Y∣X,A=a]Pr⁡(A=a∣X)\E[Y\mid X]=\sum_a\E[Y\mid X,A=a]\Pr(A=a\mid X), which still depends on group membership through Pr⁡(A∣X)\Pr(A\mid X) whenever XX predicts AA, as ZIP codes and names often do. Feedback loops: predictions shape the next round of data. Ensign et al. (2018) modeled predictive policing as an urn process in which patrols go where incidents were recorded and incidents are recorded only where patrols go, and showed that patrols can be sent back to the same neighborhoods again and again regardless of the true crime rates.

Check your understanding

In Obermeyer et al.'s study, which source of bias produced the disparity?

  1. Representation bias: too few Black patients in the training data
  2. Measurement bias: the label, cost, reflected health need differently across groups
  3. Aggregation bias: one model for groups whose features relate to the outcome differently
  4. Evaluation bias: an unrepresentative benchmark
Show the answer

B. Measurement bias: the label, cost, reflected health need differently across groups

The algorithm predicted cost accurately, but cost encodes unequal access to care: equal need produced lower spending for Black patients. Changing the label to a measure of health changed who was selected. More data or a bigger model trained on the same label would not have.

Three families of group criteria

Fix notation: features XX, a group attribute AA, a binary outcome YY, a score R=r(X)R=r(X), which may or may not use AA, and a decision Y^=1[R≥t]\hat Y=\mathbf 1[R\ge t]. Group aa's base rate is pa=Pr⁡(Y=1∣A=a)p_a=\Pr(Y=1\mid A=a). Most group criteria are conditional-independence statements about these variables (Barocas, Hardt & Narayanan, 2023):

FamilyConditionFor a binary decisionNames
IndependenceR⊥ ⁣ ⁣ ⁣⊥AR\indep APr⁡(Y^=1∣A=a)\Pr(\hat Y=1\mid A=a) equal across groupsdemographic parity, statistical parity
SeparationR⊥ ⁣ ⁣ ⁣⊥A∣YR\indep A\mid Yequal TPR Pr⁡(Y^=1∣Y=1,A=a)\Pr(\hat Y=1\mid Y=1,A=a) and equal FPR Pr⁡(Y^=1∣Y=0,A=a)\Pr(\hat Y=1\mid Y=0,A=a)equalized odds; equal TPR alone is equal opportunity (Hardt, Price & Srebro, 2016)
SufficiencyY⊥ ⁣ ⁣ ⁣⊥A∣RY\indep A\mid Requal PPV Pr⁡(Y=1∣Y^=1,A=a)\Pr(Y=1\mid\hat Y=1,A=a) and equal NPVcalibration within groups when Pr⁡(Y=1∣R=r,A=a)=r\Pr(Y=1\mid R=r,A=a)=r; equal PPV alone is predictive parity
Each family encodes a different intuition. Independence: groups receive the benefit at equal rates. Separation: people with the same outcome face the same chances of each decision, so errors fall evenly. Sufficiency: a score means the same thing whoever receives it, so a decision maker gains nothing by also looking at the group.

Can a decision satisfy two families at once? Independence and sufficiency together force equal base rates: Pr⁡(Y=1∣A=a)=∑rPr⁡(Y=1∣R=r,A=a)Pr⁡(R=r∣A=a)=∑rPr⁡(Y=1∣R=r)Pr⁡(R=r)\Pr(Y=1\mid A=a)=\sum_r\Pr(Y=1\mid R=r,A=a)\Pr(R=r\mid A=a)=\sum_r\Pr(Y=1\mid R=r)\Pr(R=r), the same for every group. The clash between independence and separation is just as short.

DerivationParity and equalized odds clash
  1. Pr⁡(Y^=1∣A=a)=τ pa+ϕ (1−pa)\Pr(\hat Y=1\mid A=a)=\tau\,p_a+\phi\,(1-p_a)

    Suppose the decision satisfies equalized odds, with the same TPR τ\tau and FPR ϕ\phi in every group. By the law of total probability, group aa's approval rate is

  2. τpa+ϕ(1−pa)=τpb+ϕ(1−pb)  ⟺  (τ−ϕ)(pa−pb)=0\tau p_a+\phi(1-p_a)=\tau p_b+\phi(1-p_b)\iff(\tau-\phi)(p_a-p_b)=0

    Demographic parity between groups aa and bb then requires

  3. pa≠pb ⟹ τ=ϕ ⟹ Y^⊥ ⁣ ⁣ ⁣⊥Yp_a\ne p_b\ \Longrightarrow\ \tau=\phi\ \Longrightarrow\ \hat Y\indep Y

    If pa≠pbp_a\ne p_b, then τ=ϕ\tau=\phi: the decision approves positives and negatives at the same rate, so it is independent of YY, and its ROC point lies on the diagonal. Apart from such uninformative rules, demographic parity and equalized odds are incompatible whenever base rates differ.

Predict before you look

In the loan scenario below, 50% of group A and 30% of group B would repay. A rule with TPR 80% and FPR 20% in both groups approves 50% of group A. What fraction of group B does it approve, in percent?

Show the answer

38 %

0.8×0.3+0.2×0.7=0.24+0.14=0.380.8\times0.3+0.2\times0.7=0.24+0.14=0.38. Equal error rates, unequal approval rates: parity fails by 12 points, exactly (τ−ϕ)(pA−pB)=0.6×0.2(\tau-\phi)(p_A-p_B)=0.6\times0.2. The third pairing, separation against sufficiency, is the subject of the impossibility theorems.

Thresholds, accuracy and the price of a criterion

Which threshold should each group get? Start from the unconstrained optimum. If approving a case with Y=0Y=0 costs cFPc_{\mathrm{FP}} and rejecting one with Y=1Y=1 costs cFNc_{\mathrm{FN}}, approving xx has expected cost (1−η(x))cFP(1-\eta(x))c_{\mathrm{FP}} and rejecting it η(x)cFN\eta(x)c_{\mathrm{FN}}, where η(x)=Pr⁡(Y=1∣X=x)\eta(x)=\Pr(Y=1\mid X=x). So approve exactly when η(x)≥cFP/(cFP+cFN)\eta(x)\ge c_{\mathrm{FP}}/(c_{\mathrm{FP}}+c_{\mathrm{FN}}), which is 12\tfrac12 for accuracy. Under a constraint such as parity or equal error rates the optimal rule is still a threshold on η\eta, but the thresholds become group-specific (Corbett-Davies et al., 2017): the constraint acts like a price that shifts each group's cutoff.

DerivationGroup thresholds in the widget
  1. pa f1,a(s) ≥ (1−pa) f0,a(s)p_a\,f_{1,a}(s)\ \ge\ (1-p_a)\,f_{0,a}(s)

    In the widget below, scores are normal within each outcome and group. In group A, applicants who would repay average 66 and those who would default 40, both with SD 12; in group B the averages are 60 and 43 with SD 14, so B's scores separate the outcomes less well. By Bayes' rule, η≥12\eta\ge\tfrac12 means

  2. (s−μ0)2−(s−μ1)22σ2≥ln⁡1−pp  ⟺  s ≥ μ0+μ12+σ2μ1−μ0ln⁡1−pp\frac{(s-\mu_0)^2-(s-\mu_1)^2}{2\sigma^2}\ge\ln\frac{1-p}{p}\iff s\ \ge\ \frac{\mu_0+\mu_1}2+\frac{\sigma^2}{\mu_1-\mu_0}\ln\frac{1-p}{p}

    With fy,af_{y,a} the normal density of mean μy\mu_y and common SD σ\sigma (dropping the group index), take logarithms. The quadratic terms cancel, so the condition is linear in ss:

  3. tB=43+602+19617ln⁡0.70.3≈51.5+9.8=61.3(the widget’s best: 62)t_B=\frac{43+60}2+\frac{196}{17}\ln\frac{0.7}{0.3}\approx51.5+9.8=61.3\qquad(\text{the widget's best: }62)

    Group A (p=0.5p=0.5): the log term vanishes and tA=53t_A=53; the widget's integer thresholds 51 to 54 tie for A's best accuracy, 86.0%. Group B (p=0.3p=0.3): the cutoff rises for two reasons, the lower base rate and the noisier score, which multiplies the log-odds by σ2/(μ1−μ0)=196/17≈11.5\sigma^2/(\mu_1-\mu_0)=196/17\approx11.5 instead of A's 144/26≈5.5144/26\approx5.5:

Constraint (gap at most 2 points)Best thresholds A / BOverall accuracyApproval rates A / B
none, per-group thresholds51 / 6281.8%54.0% / 19.5%
one shared threshold56 / 5680.8%44.5% / 31.0%
demographic parity56 / 5179.0%44.5% / 42.5%
equal opportunity59 / 5378.8%39.0% / 37.5%
equalized odds76 / 7367.3%10.0% / 6.5%
What each criterion costs in the widget, found by searching all integer threshold pairs; approving no one would score 60%. Equalized odds is so expensive because B's ROC curve lies below A's at every false-positive rate, so deterministic thresholds match both rates only near the extremes. Randomized thresholds do better, as Bias Mitigation Techniques shows.

Individual fairness

DerivationProof
  1. ES[m]−ET[m]=E(x,x′)∼π[m(x)−m(x′)]≤E(x,x′)∼π[d(x,x′)]\E_S[m]-\E_T[m]=\E_{(x,x')\sim\pi}\big[m(x)-m(x')\big]\le\E_{(x,x')\sim\pi}\big[d(x,x')\big]

    Let π\pi be any coupling of SS and TT: a joint distribution of pairs (x,x′)(x,x') with marginals SS and TT. The difference in approval rates is then an average of differences over pairs:

  2. ∣ES[m]−ET[m]∣≤inf⁡πEπ[d(x,x′)]=Wd(S,T)■\big|\E_S[m]-\E_T[m]\big|\le\inf_\pi\E_\pi\big[d(x,x')\big]=W_d(S,T)\qquad\blacksquare

    The infimum over couplings is, by definition, the earthmover distance; repeat with SS and TT swapped:

An individually fair classifier can therefore treat two groups very differently on average only if they are far apart under dd, for instance because their qualifications for the task differ. Dwork et al. compute the loss-minimizing Lipschitz classifier with a linear program. The difficulty is dd itself: it must encode which differences between people are relevant to the decision, which is the contested question to begin with. Dwork et al. imagined it supplied by a regulator or by society; later work tries to learn it from human judgments about which pairs of people should be treated alike.

Think first Is a classifier that approves everyone individually fair? Does it satisfy demographic parity?

Yes to both: a constant mm is 0-Lipschitz, and it approves every group at the same rate. Like the group criteria, individual fairness constrains a decision rule without requiring it to be useful. It has to be combined with accuracy or utility, and the real question is what the constraint costs.

Auditing in practice

An audit starts with disaggregated evaluation: the confusion matrix, error rates and calibration per group, and per intersection of groups, since harms concentrate there. Gender Shades found the largest error rates at an intersection, darker-skinned women, higher than for women or for darker-skinned people taken as a whole. Intersections are small, so report uncertainty: a true-positive rate estimated from nn positive cases has a standard error of about τ(1−τ)/n\sqrt{\tau(1-\tau)/n}.

Predict before you look

A subgroup has 60 positive cases, and the model's TPR on them is 0.75. What is the half-width of a 95% confidence interval for the TPR, in percentage points?

Show the answer

11 pts

1.960.75×0.25/60=1.96×0.056≈0.111.96\sqrt{0.75\times0.25/60}=1.96\times0.056\approx0.11, so about ±11\pm11 points. A 5-point TPR gap between two subgroups of this size is well within the noise, so audits of small groups need more data, pooled evidence or explicit tolerances, and should say so.

Context decides which criterion matters. The 1978 Uniform Guidelines on Employee Selection Procedures treat a selection rate below four-fifths of the highest group's rate as evidence of adverse impact, a parity-style test; by that yardstick the accuracy-maximizing thresholds above, approving 19.5% and 54%, have a ratio of 0.36. In lending, equal opportunity focuses on applicants who would repay. When a score informs a human decision maker, calibration within groups matters, because the same score should mean the same risk. Documentation makes these choices visible: model cards report intended uses and disaggregated performance (Mitchell et al., 2019), and datasheets record how a dataset was collected and labeled (Gebru et al., 2021).

Key takeaways

  • Bias enters at every stage: historical, representation, measurement, aggregation, learning, evaluation and deployment. A biased label or a feedback loop survives any amount of model tuning, and dropping AA leaves its proxies in place.
  • Group criteria are conditional independences: independence (R⊥ ⁣ ⁣ ⁣⊥AR\indep A: parity), separation (R⊥ ⁣ ⁣ ⁣⊥A∣YR\indep A\mid Y: equalized odds and equal opportunity) and sufficiency (Y⊥ ⁣ ⁣ ⁣⊥A∣RY\indep A\mid R: calibration and predictive parity).
  • With unequal base rates, parity plus equalized odds forces an uninformative classifier, and independence plus sufficiency is impossible; separation against sufficiency is the impossibility theorem of the Deep Layer.
  • The accuracy-optimal rule thresholds Pr⁡(Y=1∣x)\Pr(Y=1\mid x), and constraints give group-specific thresholds. In the widget: 81.8% unconstrained, 79.0% with parity, 78.8% with equal opportunity, 67.3% with deterministic equalized odds.
  • Individual fairness is a Lipschitz condition that bounds group disparities by an earthmover distance; its hard part is the similarity metric.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

Equal opportunity (Hardt, Price & Srebro, 2016) requires equality across groups of which quantity?

  1. The approval rate Pr⁡(Y^=1∣A=a)\Pr(\hat Y=1\mid A=a)
  2. The true-positive rate Pr⁡(Y^=1∣Y=1,A=a)\Pr(\hat Y=1\mid Y=1,A=a)
  3. The positive predictive value Pr⁡(Y=1∣Y^=1,A=a)\Pr(Y=1\mid\hat Y=1,A=a)
  4. The false-positive rate Pr⁡(Y^=1∣Y=0,A=a)\Pr(\hat Y=1\mid Y=0,A=a)
Show the answer

B. The true-positive rate Pr⁡(Y^=1∣Y=1,A=a)\Pr(\hat Y=1\mid Y=1,A=a)

Equal opportunity is the positive-outcome half of equalized odds: qualified applicants are approved at the same rate in every group. Equalizing approval rates is demographic parity, equalizing PPV is predictive parity, and equalized odds adds equal FPR.

Question 2

Base rates differ between two groups. Which pair of criteria can an informative binary classifier never satisfy together?

  1. Equal opportunity and high accuracy
  2. Demographic parity and equalized odds
  3. Individual fairness and demographic parity
  4. Calibration and high accuracy
Show the answer

B. Demographic parity and equalized odds

Equalized odds makes each group's approval rate τpa+ϕ(1−pa)\tau p_a+\phi(1-p_a), and parity then forces (τ−ϕ)(pa−pb)=0(\tau-\phi)(p_a-p_b)=0, so τ=ϕ\tau=\phi: the classifier is independent of the outcome.

Question 3

In the widget, why is group B's accuracy-maximizing threshold (62) higher than group A's (about 53)?

  1. B's base rate is lower and its scores separate repayers from defaulters less well, both of which raise the score at which Pr⁡(Y=1∣s)\Pr(Y=1\mid s) reaches 12\tfrac12
  2. Smaller groups always need higher thresholds
  3. B's scores are on a different scale
  4. Higher thresholds always increase accuracy
Show the answer

A. B's base rate is lower and its scores separate repayers from defaulters less well, both of which raise the score at which Pr⁡(Y=1∣s)\Pr(Y=1\mid s) reaches 12\tfrac12

The Bayes cutoff is μ0+μ12+σ2μ1−μ0ln⁡1−pp\frac{\mu_0+\mu_1}2+\frac{\sigma^2}{\mu_1-\mu_0}\ln\frac{1-p}{p}. For B the log term ln⁡(0.7/0.3)\ln(0.7/0.3) is positive, and the noisier score multiplies it by 196/17≈11.5196/17\approx11.5, giving about 61.3.

Question 4

A classifier is Lipschitz with respect to a similarity metric dd. When can it approve two groups at very different average rates?

  1. Never
  2. Only if the groups are far apart in earthmover distance under dd
  3. Only if it uses the group attribute
  4. Whenever the base rates differ
Show the answer

B. Only if the groups are far apart in earthmover distance under dd

Coupling the groups gives ∣ESm−ETm∣≤Eπd(x,x′)|\E_Sm-\E_Tm|\le\E_\pi d(x,x') for every coupling π\pi, hence at most Wd(S,T)W_d(S,T). Groups that are close under dd must be treated alike on average; groups far apart need not be.

Question 5

A model never sees the group attribute. Which criterion does that guarantee?

  1. Demographic parity
  2. Equalized odds
  3. Calibration within groups
  4. None of them
Show the answer

D. None of them

Fairness through unawareness constrains the inputs, not the outcomes. Proxies such as ZIP code carry group information, and a predictor trained on biased labels reproduces them. Every group criterion is a property of the joint distribution of RR, AA and YY, and has to be checked on that distribution.

Go deeper

Further reading

  • S. Barocas, M. Hardt & A. Narayanan, Fairness and Machine Learning: Limitations and Opportunities (MIT Press, 2023), free at fairmlbook.org.
  • C. Dwork, M. Hardt, T. Pitassi, O. Reingold & R. Zemel, "Fairness through awareness," ITCS (2012).
  • M. Hardt, E. Price & N. Srebro, "Equality of opportunity in supervised learning," NeurIPS (2016).
  • Z. Obermeyer, B. Powers, C. Vogeli & S. Mullainathan, "Dissecting racial bias in an algorithm used to manage the health of populations," Science (2019).