- Identify the main sources of algorithmic bias, from historical data and proxies to feedback loops.
- Compute selection rates, true and false positive rates and precision per group from a confusion matrix.
- Apply the four-fifths rule of thumb and explain why it is a screening signal rather than proof.
- Explain, with a worked example, why calibration-style and error-rate fairness criteria conflict when base rates differ.
- Implement a per-group fairness report in Python and account for sampling noise in small groups.
- Choose fairness measures and mitigations appropriate to a use case, and document the choice.
Before this: How Machines Learn, Model Evaluation and Metrics
AI systems now help decide who gets a job interview, a loan, extra medical attention or a second look from security. If a system works noticeably worse for some groups of people, those people pay the cost, often without knowing a machine was involved.
What "bias" means here
In statistics, bias simply means a systematic error: results that are consistently off in one direction. Algorithmic bias is when an automated system produces systematically worse or less favorable outcomes for certain groups, such as people of a particular sex, age, skin tone, language or region. Fairness is the goal of avoiding unjustified differences in how a system treats or performs for those groups. As you will see, people can reasonably disagree about which definition of fairness fits a given situation.
A useful analogy: a model is like a student who learned everything from one library. If the library's books are old, one-sided or missing whole subjects, the student will repeat those gaps with complete confidence, and sometimes exaggerate them.
Where bias comes from
- Historical data. Models learn patterns from past decisions. If those decisions were skewed, the model learns the skew.
- Unrepresentative samples. If some groups are rare in the training data, the model gets less practice on them and makes more mistakes.
- The wrong target (proxy). Builders often predict something easy to measure that stands in for what they really care about. If the stand-in tracks some groups differently, errors follow.
- Measurement and labels. The people or tools that label training examples can be inconsistent across groups.
- Deployment and feedback loops. A system used in a different setting from the one it was tested in, or whose decisions shape its future training data, can drift.
- For chatbots specifically. Large language models learn from huge amounts of internet text, which overrepresents some languages, regions and viewpoints, and then from human raters' preferences during fine-tuning. Both can shape which assumptions and associations show up in answers.
Documented examples
| Year | System | What was found |
|---|---|---|
| 2018 | Commercial face analysis | The Gender Shades study tested three gender-classification products. Error rates reached 34.7% for darker-skinned women versus at most 0.8% for lighter-skinned men. |
| 2018 | Experimental hiring tool | Reuters reported that Amazon dropped a resume-ranking project trained on ten years of mostly male applications; it reportedly downgraded resumes containing the word "women's". Sources said recruiters never relied on its rankings alone. |
| 2019 | Face recognition (189 algorithms) | The US National Institute of Standards and Technology (NIST) found that, in one-to-one matching, many algorithms produced false matches for Asian and African American faces 10 to 100 times more often than for white faces; the most equitable algorithms were also among the most accurate. |
| 2019 | Hospital care-management algorithm | A study in Science found the algorithm used past health spending as a proxy for health need. Because less was spent on Black patients with the same needs, they were scored as healthier. Fixing the target would have raised the share of Black patients flagged for extra help from 17.7% to 46.5%. |
| 2016 | Criminal risk scores (COMPAS) | ProPublica reported that Black defendants who did not reoffend were more often labeled high risk than white defendants who did not reoffend. The developer responded that its scores meant the same thing for both groups. Both claims can be true at once, which leads to the measurement problem below. |
Two lessons stand out. First, bias rarely comes from anyone intending it; it comes from data and design choices. Second, it can be fixed or reduced once it is measured: the NIST study found the most equitable systems were among the most accurate, and the hospital study showed a better target removes most of the gap.
How bias is measured
You cannot manage what you do not measure. The basic method: split test results by group and compare.
Worked example. A resume screener reviews 1,000 applicants, 500 from group A and 500 from group B.
- Group A: 150 advance, a selection rate of 30%.
- Group B: 90 advance, a selection rate of 18%.
- Ratio: 18 ÷ 30 = 0.60.
US employment regulators have long used a "four-fifths" rule of thumb: if one group's selection rate is below 80% of the highest group's, that is a signal to investigate. Here 0.60 is well below 0.80, so the tool needs a closer look. It is a screening signal, not proof of discrimination.
Common fairness measures include:
- Selection-rate parity: groups are chosen at similar rates.
- Equal error rates: groups face similar rates of false alarms and misses.
- Calibration: a given score means the same real-world likelihood in every group.
When groups have different underlying rates of the outcome, researchers have shown that a tool generally cannot satisfy equal error rates and calibration at the same time. That is exactly what happened in the COMPAS debate. Choosing a fairness measure is therefore partly a values decision about which errors matter most, not only a technical one.
How bias is reduced
- Better data: collect more examples from underrepresented groups, check labels and remove proxies that stand in for protected traits.
- Better targets: make sure the model predicts what you actually care about.
- Training adjustments: reweight examples or add constraints that penalize unequal error rates.
- Threshold and output checks: test results by group before and after launch, and adjust decision thresholds where appropriate and lawful.
- Process safeguards: impact assessments before deployment, human review for consequential decisions, a way for people to contest outcomes, and ongoing monitoring.
- Documentation: record what data was used, what was tested and where the system should not be used.
None of these is a one-time fix. Populations and uses change, so testing has to continue.
Going deeper
The confusion matrix, per group
Most fairness measures come from one table. For a yes/no decision (advance, approve, flag), compare each person's prediction with what actually turned out to be true:
| Actually positive | Actually negative | |
|---|---|---|
| Predicted positive | True positive (TP) | False positive (FP) |
| Predicted negative | False negative (FN) | True negative (TN) |
From these four counts, computed separately for each group:
- Selection rate , the share of the group that gets a "yes";
- True positive rate (TPR, also called recall) , the share of genuinely qualified people who are caught;
- False positive rate (FPR) , the share of genuinely unqualified people wrongly flagged;
- Positive predictive value (PPV, also called precision) , the share of "yes" decisions that were right;
- False negative rate .
Selection-rate parity compares the first line across groups; "equal error rates" compares TPR and FPR; equal PPV (sometimes called predictive parity) is a close cousin of calibration: it means a "yes" is equally trustworthy in every group.
Why the criteria collide
Write for a group's base rate (the share who are actually positive). Chouldechova (2017) pointed out that the four quantities are tied together by an identity that follows directly from the definitions:
If two groups have the same PPV and the same FNR but different base rates , their false positive rates must differ.
Worked example. A risk tool is applied to 1,000 people in group A and 1,000 in group B. In A, 50% are actually positive (); in B, 20% are (). The tool achieves the same precision (PPV = 0.8) and the same true positive rate (0.8, so FNR = 0.2) in both groups.
- Group A: .
- Group B: .
Check with counts. A has 500 positives: TP = 400, FN = 100; PPV = 0.8 means FP = 100; with 500 negatives, FPR = 100/500 = 0.20. B has 200 positives: TP = 160, FN = 40; FP = 40; with 800 negatives, FPR = 40/800 = 0.05. Selection rates are for A and for B, a ratio of 0.40, far below four-fifths.
So the same tool is "fair" by precision and true positive rate, "unfair" by false positive rate (an innocent member of A is four times as likely to be flagged), and "unfair" by selection rate. This is the COMPAS debate in miniature. Kleinberg, Mullainathan and Raghavan (2016) proved the general version: apart from special cases (perfect prediction, or equal base rates), a risk score cannot be calibrated within groups and also balance error rates across them. Someone has to decide which errors matter most in the setting, and write that decision down.
Measuring it in code
import numpy as np
def make_group(name, tp, fn, fp, tn):
y_true = np.array([1] * (tp + fn) + [0] * (fp + tn))
y_pred = np.array([1] * tp + [0] * fn + [1] * fp + [0] * tn)
return y_true, y_pred, np.array([name] * len(y_true))
def group_report(y_true, y_pred, group):
rates = {}
for g in np.unique(group):
m = group == g
t, p = y_true[m], y_pred[m]
tp = np.sum((t == 1) & (p == 1)); fp = np.sum((t == 0) & (p == 1))
fn = np.sum((t == 1) & (p == 0)); tn = np.sum((t == 0) & (p == 0))
rates[g] = (tp + fp) / m.sum()
print(f"{g}: n={m.sum()} selected={rates[g]:.2f} TPR={tp/(tp+fn):.2f} "
f"FPR={fp/(fp+tn):.2f} PPV={tp/(tp+fp):.2f}")
return rates
a = make_group("A", tp=400, fn=100, fp=100, tn=400)
b = make_group("B", tp=160, fn=40, fp=40, tn=760)
y_true, y_pred, group = (np.concatenate(x) for x in zip(a, b))
rates = group_report(y_true, y_pred, group)
print("selection-rate ratio:", round(min(rates.values()) / max(rates.values()), 2))
This reproduces the worked example: both groups show TPR 0.80 and PPV 0.80, while FPR is 0.20 versus 0.05 and the selection-rate ratio is 0.4. In real projects, y_true and y_pred come from a held-out test set, and libraries such as Fairlearn compute the same per-group breakdowns for any metric.
Small groups are noisy
A rate measured on few people is uncertain. Its standard error is for a rate measured on people. For a group of 40 with a 25% selection rate, that is , so the true rate could plausibly be anywhere from about 12% to 38%. Report group sizes alongside rates, pool data over time where you can, and never conclude "no bias found" from a handful of cases.
Where mitigation happens
Mitigations are usually grouped by stage: pre-processing (fix the data: rebalance, relabel, remove proxies), in-processing (train with a fairness constraint or penalty), and post-processing (adjust decision thresholds). Each has costs, and some are legally restricted. In US hiring, for example, federal law (42 U.S.C. § 2000e-2(l), added by the Civil Rights Act of 1991) makes it unlawful to adjust scores, use different cutoff scores or otherwise alter the results of employment-related tests on the basis of race, colour, religion, sex or national origin, so group-specific thresholds can themselves be unlawful. Involve legal advice before using them.
Common pitfalls
- Reporting only overall accuracy. A system can be 95% accurate overall and much worse for a small group.
- "Fairness through unawareness." Deleting the protected attribute does not help if postcode, school or name still stands in for it, and it stops you measuring the problem.
- Picking the metric after seeing the results. Decide in advance which measures matter and why.
- Ignoring intersections. Gender Shades found the worst errors for darker-skinned women, a gap that averages by sex or by skin tone alone would hide.
- Trusting small samples. Wide uncertainty can hide a real gap or invent one.
- Treating the four-fifths rule as a safe harbour. Passing it does not prove a tool is fair or lawful; failing it does not prove discrimination.
- Testing once. Populations, inputs and uses drift; schedule re-testing.
In practice
If you use AI tools:
- For decisions about people (hiring, grading, lending, housing), treat AI output as one input, not the verdict.
- Try the same request with details changed, such as a different name or region, and see whether the answer shifts.
- Ask vendors what fairness testing they did, on which groups, and how you can appeal a result.
If you build with AI:
- Decide in advance which groups and which fairness measures matter for your use case, and write that down.
- Report accuracy and error rates per group, not just one overall number.
- Keep a human in the loop and an appeal route for consequential decisions, and keep monitoring after launch.
Key takeaways
- Algorithmic bias usually comes from data and design choices, such as skewed history, missing groups or a poor proxy target, rather than intent.
- Well-documented audits of face analysis, face recognition and a hospital algorithm found large performance gaps between groups.
- Bias is measured by splitting results by group and comparing selection rates, error rates and calibration.
- Different fairness measures can conflict, so choosing one involves a judgement about which errors matter most.
- Mitigation is ongoing: better data and targets, per-group testing, human review, appeal routes and monitoring.
Terms in this lesson
- Algorithmic bias
- Systematically worse or less favorable outcomes from an automated system for particular groups of people.
- Proxy
- An easy-to-measure stand-in for the thing you actually want to predict, such as spending instead of health need.
- Selection rate
- The share of a group that a system approves, advances or selects.
- Four-fifths rule
- A US employment rule of thumb that flags for review any group selected at less than 80% of the rate of the most-selected group.
- False positive
- An error where the system says yes, or flags someone, when the correct answer was no.
- Calibration
- The property that a given score corresponds to the same real-world likelihood for every group.
- Confusion matrix
- A table counting true positives, false positives, false negatives and true negatives, from which most error and fairness metrics are computed.
- True positive rate (recall)
- The share of actually positive cases that a system correctly identifies: TP / (TP + FN).
- Positive predictive value (precision)
- The share of a system's positive predictions that are correct: TP / (TP + FP).
Check your understanding
- 1.
In the 2019 hospital algorithm study, what was the main source of bias?
- 2.
A screening tool selects 40% of group A and 28% of group B. What does the four-fifths rule of thumb suggest?
- 3.
Why did the COMPAS debate show that fairness is partly a values question?
- 4.
In one group, 200 people were actually negative and the tool wrongly flagged 30 of them. What is the false positive rate for that group?
- 5.
A team removes the applicant's sex from a hiring model's inputs and declares the model fair. What is the main problem?
Exercises
Work each problem before opening the solution.
- Exercise 1Core
Compute selection rate, TPR, FPR and PPV for each group, then the four-fifths ratio. Group X (1,000 people): TP 90, FP 30, FN 10, TN 870. Group Y (500 people): TP 45, FP 30, FN 15, TN 410. What do the numbers suggest?
Show solution
Group X: selection ; TPR ; FPR ; PPV .
Group Y: selection ; TPR ; FPR ; PPV .
Four-fifths ratio: , exactly at the threshold, so the selection-rate screen does not flag it. But every error measure is worse for Y: qualified Y members are missed more often (TPR 0.75 vs 0.90), unqualified Y members are wrongly selected about twice as often (FPR 0.068 vs 0.033), and a "yes" for Y is less reliable (PPV 0.60 vs 0.75). Similar selection rates can hide very different error patterns, which is why you report several measures.
- Exercise 2Core
Using Chouldechova's identity, compute the false positive rate for two groups that share PPV = 0.7 and FNR = 0.25, with base rates (a) and (b) .
Show solution
and for both.
(a) .
(b) .
The group with the higher base rate has nearly four times the false positive rate, even though precision and miss rate are identical.
- Exercise 3Core
Extend
group_reportso it also prints, for each group, the ratio of its selection rate to the highest group's selection rate, and marks any group below 0.8 withCHECK. Test it on the lesson's groups A and B.Show solution
def four_fifths(rates, threshold=0.8): top = max(rates.values()) for g, r in rates.items(): ratio = r / top flag = "CHECK" if ratio < threshold else "ok" print(f"{g}: selection {r:.2f}, ratio {ratio:.2f} {flag}") rates = group_report(y_true, y_pred, group) four_fifths(rates) # A: selection 0.50, ratio 1.00 ok # B: selection 0.20, ratio 0.40 CHECKKeeping the ratio calculation separate from the metric calculation makes it easy to apply other screens later, such as differences in FPR.
- Exercise 4Challenge
In one month, a screening tool selected 25% of a minority group of 40 applicants and 35% of a majority group of 2,000. (a) Compute the four-fifths ratio. (b) Using standard errors, how confident can you be that the minority rate is really lower? (c) What should the team do?
Show solution
(a) , below 0.8, so the screen flags it.
(b) Minority SE ; an approximate 95% range is , about 0.12 to 0.38. Majority SE , so 0.35 is measured precisely. The ratio could plausibly be anywhere from about to . The data are consistent with a large disparity and with none, so this month alone is inconclusive.
(c) Do not dismiss it, and do not declare discrimination. Pool several months (or use a statistical test designed for small counts), look at error rates if outcome data exist, examine which inputs drive the minority group's rejections (possible proxies), and set a date to re-check. Document the analysis and the decision.
Further reading
- bookSolon Barocas, Moritz Hardt & Arvind Narayanan, Fairness and Machine Learning: Limitations and Opportunities (2023)
- paperJon Kleinberg, Sendhil Mullainathan & Manish Raghavan, Inherent Trade-Offs in the Fair Determination of Risk Scores (2016)
- paperAlexandra Chouldechova, Fair prediction with disparate impact: A study of bias in recidivism prediction instruments (2017)
- docsFairlearn user guide: Assessment
- paperMargaret Mitchell et al., Model Cards for Model Reporting (2019)
Go further
Sources
- Buolamwini & Gebru, Gender Shades: Intersectional Accuracy Disparities in Commercial Gender Classification (PMLR, 2018)
- NIST Study Evaluates Effects of Race, Age, Sex on Face Recognition Software (Dec 2019)
- Obermeyer et al., Dissecting racial bias in an algorithm used to manage the health of populations (Science, 2019)
- Amazon scraps secret AI recruiting tool that showed bias against women (Reuters, via Euronews, Oct 2018)
- Case study: COMPAS and the fairness wars (CUNY Manifold)
- Chouldechova, Fair prediction with disparate impact (arXiv 1703.00056)
- Kleinberg, Mullainathan & Raghavan, Inherent Trade-Offs in the Fair Determination of Risk Scores (arXiv 1609.05807)
- Fairlearn user guide: Assessment
- Wisconsin Attorney General opinion, 80 Op. Att'y Gen. 264 (1992), quoting 42 U.S.C. § 2000e-2(l) (Civil Rights Act of 1991, sec. 106)
Fact-checked and last reviewed 2026-11-05