Sub topic 5
Demographic parity
This chapter assumes you can compute a confusion matrix and the selection rate, and that you can use NumPy. It also assumes you have already split your evaluation data by a sensitive attribute, as covered in the earlier chapters.
What the criterion says
Demographic parity (also called statistical parity) requires that a model selects people from each group at the same rate. A model satisfies it when
P(ŷ = 1 | group = A) = P(ŷ = 1 | group = B)
The selection rate is the share of a group that receives the positive prediction, such as "approve the loan" or "show the job ad". The criterion ignores the true labels y_true. It looks only at the model's decisions and the group membership.
Measuring it
Two summaries are common:
- Difference: the largest selection rate minus the smallest. A value of 0 means perfect parity.
- Ratio: the smallest selection rate divided by the largest. A value of 1 means perfect parity.
The ratio underlies the "four-fifths rule" used in US employment guidance, which flags a ratio below 0.8. Treat 0.8 as a screening heuristic. It is not a legal or statistical test of fairness.
import numpy as np
def selection_rates(y_pred, group):
y_pred = np.asarray(y_pred)
group = np.asarray(group)
return {str(g): float(y_pred[group == g].mean()) for g in np.unique(group)}
y_pred = np.array([1, 0, 1, 1, 0, 1, 0, 0, 1, 0])
group = np.array(["A"] * 5 + ["B"] * 5)
rates = selection_rates(y_pred, group)
dp_difference = max(rates.values()) - min(rates.values())
dp_ratio = min(rates.values()) / max(rates.values())
print(rates)
print(f"difference = {dp_difference:.2f}, ratio = {dp_ratio:.2f}")The output is {'A': 0.6, 'B': 0.4} followed by difference = 0.20, ratio = 0.67. Group B is selected two-thirds as often as group A, so this model would fail the four-fifths screen.
When it fits and when it misleads
Demographic parity is easy to compute and needs no ground-truth labels. That makes it useful when labels are themselves suspect, for example when past hiring decisions encoded bias. It also fits settings where you want equal access to a benefit regardless of group.
It has a clear weakness. If the true base rates differ between groups, a perfectly accurate model will not satisfy it. Forcing parity then means accepting more errors in one group, such as rejecting qualified applicants in one group or approving unqualified ones in another. The criterion also allows a model to reach parity by picking the right number of people at random in one group, which satisfies the rule and still harms individuals.
Common errors
- Reading a small gap as proof. With few samples per group, a 0.05 difference can be noise. The chapter on uncertainty covers confidence intervals.
- Dividing by zero. If the highest selection rate is 0, the ratio is undefined. Guard for it.
- Using scores instead of decisions. Selection rate depends on the decision threshold. Report which threshold you used.
- Skipping the context. Choose demographic parity because the deployment calls for it, not because it is the easiest metric to compute.
Exercise
A model approves 45 of 100 applicants in group A and 27 of 90 applicants in group B. Compute the demographic parity difference and ratio, and say whether the four-fifths screen is passed.
Show answer
Group A selection rate is 45/100 = 0.45. Group B selection rate is 27/90 = 0.30. The difference is 0.15. The ratio is 0.30/0.45 ≈ 0.67, which is below 0.8, so the screen is failed.