Sub topic 5
Demographic parity
This chapter assumes you can read a confusion matrix, know precision, recall, and false positive rate, and can run basic Python with NumPy. It also assumes you have already defined groups, as covered in the chapter on sensitive attributes.
What demographic parity requires
Demographic parity (also called statistical parity or independence) asks that the model's positive predictions are spread across groups at the same rate. Let Ŷ be the prediction and A the group. The criterion is:
P(Ŷ = 1 | A = a) = P(Ŷ = 1 | A = b) for every pair of groups a and b.
The quantity P(Ŷ = 1 | A = g) is the selection rate of group g. It is the fraction of people in that group who receive the positive outcome, such as an approved loan or an interview invitation.
Demographic parity ignores the true labels. It does not ask whether the model is right, only whether it selects groups at equal rates. This has two consequences:
- You can measure it without ground truth. This helps when labels are delayed, missing, or themselves produced by biased decisions.
- A perfect classifier can violate it. If the true positive rate in the population differs by group (different base rates), a model that predicts every label correctly will select the groups at different rates.
Measuring the gap
Two summaries are common. Both are computed from the selection rates.
| Summary | Formula | Perfect parity | Typical use |
|---|---|---|---|
| Difference | max rate − min rate | 0 | Reporting an absolute gap in percentage points |
| Ratio | min rate / max rate | 1 | Screening rules such as the four-fifths rule |
The ratio is also called the disparate impact ratio. In US employment guidance, a ratio below 0.8 (the four-fifths rule) is a common trigger for closer review. Treat it as a screening heuristic from one legal context, not as a universal definition of fair. Which threshold applies to your system depends on your jurisdiction and domain.
With more than two groups, compare the highest and lowest selection rates, or compare each group with a reference group. State which one you used.
import numpy as np
def selection_rates(y_pred, group):
y_pred = np.asarray(y_pred)
group = np.asarray(group)
return {g: float(y_pred[group == g].mean()) for g in np.unique(group)}
def parity_summary(y_pred, group):
rates = selection_rates(y_pred, group)
hi, lo = max(rates.values()), min(rates.values())
return {
"rates": rates,
"difference": hi - lo,
"ratio": lo / hi if hi > 0 else float("nan"),
}
group = np.array(["A"] * 200 + ["B"] * 100)
y_pred = np.concatenate([
np.r_[np.ones(120), np.zeros(80)], # group A: 120 of 200 selected
np.r_[np.ones(36), np.zeros(64)], # group B: 36 of 100 selected
]).astype(int)
print(parity_summary(y_pred, group))Group A has a selection rate of 0.60 and group B has 0.36. The difference is 0.24 and the ratio is 0.60, so this model fails the four-fifths screen.
Guard the ratio against a group with a selection rate of zero. The code above returns a ratio of 0 in that case, which is correct but means the ratio hides how many people were involved. Always report group sizes next to the rates.
Where the metric sits in an audit
When demographic parity is the right lens
Demographic parity is a reasonable primary criterion in these situations:
- Labels are untrustworthy. If past hiring or policing decisions produced the labels, then "accuracy" and "equal error rates" inherit that bias. Parity on outcomes does not depend on those labels.
- The harm is about access. For allocation of opportunities such as ads for jobs, interview slots, or housing listings, the question is who gets in front of the opportunity.
- A policy or regulation speaks in selection rates. Some compliance processes are phrased this way.
It is a weaker choice when the positive outcome should track a real, measurable need. In a medical screening model, forcing equal referral rates across groups with different disease prevalence either over-refers one group or under-refers another. In that setting, equal opportunity (covered in the next chapter) is usually closer to the goal.
Edge cases and common errors
Base rate differences
If the true positive rates differ across groups, the criterion forces a trade-off. Let the base rate in group g be πg. For a classifier with true positive rate TPRg and false positive rate FPR_g, the selection rate is:
selection rate = πg · TPRg + (1 − πg) · FPRg
For selection rates to be equal when πA ≠ πB, the error rates must differ between the groups. In practice this means the model must make more mistakes for at least one group than it would otherwise. This is the core tension described in the chapter on why criteria cannot all hold at once.
Equal rates with unequal quality
A model can satisfy demographic parity by selecting the right number of people from each group but the wrong people in one group. For example, selecting group B applicants at random until the quota is met gives perfect parity and poor outcomes for the selected applicants. Parity says nothing about who inside each group is selected. Always check it alongside an error-based metric.
Sampling noise
Selection rate gaps from small groups are noisy. A group of 30 people with 12 selected has a rate of 0.40, but a 95% interval of roughly 0.25 to 0.58. Do not report a gap without group sizes, and use the uncertainty methods from the later chapter before deciding that a gap is real.
Thresholds on scores
Most models output scores, and the selection rate depends on the threshold. A gap at threshold 0.5 can be absent at 0.3. When you audit, report the threshold that is used in production. If a decision threshold is not yet fixed, plot the selection rate per group across thresholds.
Conditional demographic parity
Sometimes part of the gap has a legitimate explanation, for example different job requirements across departments. Conditional demographic parity asks for equal selection rates within strata of a legitimate factor L:
P(Ŷ = 1 | A = a, L = l) = P(Ŷ = 1 | A = b, L = l) for each l.
Be careful with this. Choosing L is a judgment call, and a factor that is itself shaped by discrimination (such as a proxy for historical access) can hide real harm. Document why each conditioning variable is legitimate.
Enforcing parity with group-specific thresholds
A simple post-processing approach is to choose a separate threshold for each group so that each group reaches the same target selection rate. The example below uses synthetic scores.
import numpy as np
rng = np.random.default_rng(0)
group = np.array(["A"] * 1000 + ["B"] * 1000)
scores = np.concatenate([
rng.beta(5, 3, size=1000), # group A scores skew higher
rng.beta(3, 4, size=1000), # group B scores skew lower
])
single_threshold = 0.6
before = {g: float((scores[group == g] >= single_threshold).mean())
for g in ("A", "B")}
target_rate = 0.30
thresholds = {g: float(np.quantile(scores[group == g], 1 - target_rate))
for g in ("A", "B")}
y_adj = np.array([s >= thresholds[g] for s, g in zip(scores, group)]).astype(int)
after = {g: float(y_adj[group == g].mean()) for g in ("A", "B")}
print("single threshold:", before)
print("group thresholds:", thresholds)
print("selection rates after:", after)Both groups now sit at about 30% selection. This comes with costs you should name when you use it:
- Two people with the same score can receive different decisions, which may be unacceptable or illegal in some domains. Check the legal position before using the sensitive attribute at decision time.
- It requires the group label when the model is deployed.
- It forces equal rates and does not improve the quality of the scores. Precision and recall will change differently in each group, so re-run the full audit afterwards.
The chapter on mitigation compares this with pre-processing and in-processing methods.
Checklist for using the metric
- Define the positive outcome and who receives it (the decision, not the score).
- Fix the production threshold or decision rule.
- Compute rates and sizes for each group.
- Report both the difference and the ratio, and say which reference you used.
- Add uncertainty for small groups.
- Explain base rate differences and label quality in plain words.
- Record the result and any chosen mitigation in your audit log.
Exercise
A model approves 45 of 150 applicants in group X and 60 of 400 applicants in group Y. Compute the selection rates, the difference, and the ratio. Does the model pass the four-fifths screen, and why might a perfectly accurate model still fail demographic parity here?
Show answer
Group X: 45/150 = 0.30. Group Y: 60/400 = 0.15. The difference is 0.15 (15 percentage points). The ratio is the lower rate over the higher rate: 0.15/0.30 = 0.50, which is below 0.8, so the model fails the screen. A perfectly accurate model would still fail if the true positive rate (base rate) differed by group, because it would correctly approve more people in the group with more qualified applicants. In that case the gap reflects the data, and you need to decide whether the labels themselves are biased and whether another criterion, such as equal opportunity, better fits the harm you care about.
Exercise
Why can demographic parity be computed before any ground-truth labels arrive, and what is the risk of relying on it alone?
Show answer
It uses only predictions and group membership, so no labels are needed. The risk is that a model can match selection rates while selecting poorly qualified people in one group, so equal rates can hide unequal error rates and poor outcomes. Check an error-based metric once labels are available.