Bias and Fairness
Bias in AI means a system gives systematically worse results to some group of people, for example by gender, race, age, language or where they live. Fairness is the goal of avoiding that, and it can be measured. Bias usually comes from the data: a model trained on past human decisions learns the prejudices in them, and removing the group column doesn't remove the bias, because other columns can stand in for it.
"AI Bias in Everyday Tools" and "Data Quality and Bias in Data" introduced the problem. This lesson measures it.
Where Bias Comes From
| Source | Description |
|---|---|
| Biased labels | It is used to describe training on past decisions that were unfair, such as hiring or loan approvals |
| Unrepresentative data | Some groups have few examples, so the model learns them poorly |
| Proxy features | Columns like zip code or school that are linked to a protected group |
| Measurement bias | The data measures some groups less accurately, such as photos taken in poor light |
| Deployment bias | A model used for people or places it wasn't built for |
Fairness Measures
| Measure | Description |
|---|---|
| Selection rate | It is used to compare the share of each group that gets the positive outcome |
| Four-fifths rule | A US hiring guideline: a group's selection rate below 80% of the highest group's is a warning sign |
| Equal opportunity | It is used to compare the share of qualified people accepted in each group |
| Error rates by group | False positives and false negatives for each group, as in "Evaluating Models: Metrics" |
Different measures can conflict: a model can't always satisfy all of them at once, so teams must choose which matter most for the decision and explain why.
Example: A Biased Scholarship Model
This program makes up 4,000 scholarship applications. Both groups have the same spread of grades and essay scores, so a fair process would accept both groups at about the same rate. But past committees were biased: group B needed about 6 more points to be accepted. A model is then trained on those past decisions, without ever being given the group column.
import numpy as np
from sklearn.linear_model import LogisticRegression
# Made-up scholarship applications. Both groups have the same spread of grades and essay scores.
rng = np.random.default_rng(33)
n = 4000
group = rng.integers(0, 2, n) # 0 = group A, 1 = group B
grades = rng.normal(80, 8, n)
essay = rng.normal(70, 10, n)
area = np.where(rng.random(n) < 0.8, group, 1 - group) # where they live: matches their group 80% of the time
qualified = grades + 0.5 * essay > 117 # the fair rule the committee meant to use
# Past committees were biased: group B needed about 6 more points to be accepted
past = grades + 0.5 * essay - 6 * group + rng.normal(0, 2, n) > 117
def report(name, accepted, rows=slice(None)):
g, q, a = group[rows], qualified[rows], accepted
rates = [a[g == k].mean() for k in (0, 1)]
found = [a[(g == k) & q].mean() for k in (0, 1)] # share of qualified people accepted
print(f"{name:30} accepted A {rates[0]:5.1%} B {rates[1]:5.1%} ratio {rates[1] / rates[0]:.2f}"
f" | qualified accepted A {found[0]:5.1%} B {found[1]:5.1%}")
report("Truly qualified", qualified)
report("Past committee decisions", past)
train, test = slice(0, 3000), slice(3000, None)
def model(features, labels):
X = np.column_stack(features)
return LogisticRegression(max_iter=1000).fit(X[train], labels[train]).predict(X[test])
print("\nModels, scored on 1,000 new applicants (the group column is never given to them):")
report("Learned from past decisions", model([grades, essay, area], past), test)
report("Same, area column removed", model([grades, essay], past), test)
report("Learned from fair labels", model([grades, essay, area], qualified), test)Truly qualified accepted A 43.3% B 42.0% ratio 0.97 | qualified accepted A 100.0% B 100.0%
Past committee decisions accepted A 43.2% B 19.7% ratio 0.46 | qualified accepted A 92.9% B 47.0%
Models, scored on 1,000 new applicants (the group column is never given to them):
Learned from past decisions accepted A 32.5% B 25.2% ratio 0.78 | qualified accepted A 80.4% B 61.5%
Same, area column removed accepted A 31.0% B 27.7% ratio 0.89 | qualified accepted A 76.8% B 67.6%
Learned from fair labels accepted A 40.4% B 41.0% ratio 1.01 | qualified accepted A 100.0% B 100.0%Explanation:
| Decisions | Accepted A | Accepted B | Ratio | Qualified accepted, A vs B |
|---|---|---|---|---|
| Truly qualified | 43.3% | 42.0% | 0.97 | 100% vs 100% |
| Past committees | 43.2% | 19.7% | 0.46 | 92.9% vs 47.0% |
| Model from past decisions | 32.5% | 25.2% | 0.78 | 80.4% vs 61.5% |
| Same, area removed | 31.0% | 27.7% | 0.89 | 76.8% vs 67.6% |
| Model from fair labels | 40.4% | 41.0% | 1.01 | 100% vs 100% |
- The past decisions were badly unfair: only 47.0% of qualified group B applicants were accepted, against 92.9% of group A.
- The model learned that bias without seeing the group column. Its ratio of 0.78 is below the four-fifths line, and qualified B applicants are accepted less often (61.5% against 80.4%). It found the bias through the area column, which matches the group 80% of the time: a proxy.
- Removing the proxy helps but doesn't fix it (0.89). The labels themselves still teach the model that B applicants are less deserving.
- Training on fair labels fixes it: equal rates (1.01) and every qualified applicant accepted in both groups. The cure was in the data, not in hiding a column.
The data is made up so the true answer is known. With real data, the "truly qualified" column usually isn't available, which is exactly why measuring outcomes by group is so important.
Reducing Bias
| Stage | What to do |
|---|---|
| Before training | Check who is in the data; fix biased labels; collect more data for underrepresented groups |
| During training | Use fairness-aware methods, or reweight examples |
| After training | Measure fairness by group on a test set; adjust decision thresholds if justified |
| In use | Monitor outcomes by group; let people appeal; keep a human in important decisions |
Common Mistakes
Measuring only overall accuracy. A system can be accurate on average and unfair to a group.
Trusting "we don't use race or gender". Proxies carry the same information.
Fixing the model but not the process. If the labels come from biased decisions, the bias returns with the next training run.
Choosing a fairness measure without explaining why. Measures conflict; document the choice.
Interview Corner
How can a model be biased if it doesn't use a protected attribute?
Through proxy features correlated with the attribute, such as zip code, school or name, and through labels that came from biased past decisions. The model learns the pattern from whatever features carry it.
How would you measure fairness in a classifier?
Compare outcomes by group: selection rates (and their ratio, as in the four-fifths rule), error rates such as false positives and false negatives, and the share of qualified people accepted (equal opportunity). Choose the measures that matter for the decision, and monitor them after launch.
Practice
Exercise: a stronger proxy. Change 0.8 to 0.95 in the line that makes area, so where people live matches their group more closely. How do the ratio and the qualified acceptance rates of the first model change?
Check your understanding:
- How did the model learn the bias without the group column?
- Why didn't removing the area column fully fix the model?
- What does a ratio of 0.78 mean under the four-fifths rule?
Key Takeaways
Quick reference
| Need | Code or practice |
|---|---|
| Selection rate by group | accepted[group == g].mean() |
| Four-fifths check | rate_B / rate_A >= 0.8 |
| Equal opportunity | accepted[(group == g) & qualified].mean() |
| Find proxies | Check how well each feature predicts the group |
| Fix | Fairer labels, more data, monitoring, appeals |
Was this tutorial helpful?