Sub topic 6
Equal Opportunity and Equalized Odds
This chapter assumes you can read a confusion matrix and compute TPR (true positive rate) and FPR (false positive rate). It also assumes you have the group_rates helper from the previous chapter, which returns per-group selection rate, TPR, FPR, and precision.
Why condition on the true label
Demographic parity compares selection rates and ignores the true outcome. If base rates differ between groups, a perfect classifier fails it. Equal opportunity and equalized odds avoid this by comparing error rates among people with the same true label.
- Equal opportunity requires equal TPR across groups. Among people who truly qualify, each group has the same chance of being selected.
- Equalized odds requires equal TPR and equal FPR. Qualified people are selected at the same rate in every group, and unqualified people are wrongly selected at the same rate in every group.
Equal opportunity is a weaker condition. It is a good fit when the harm is mainly a missed benefit, such as a qualified applicant being rejected. Equalized odds also covers harms from false positives, such as a wrongful fraud flag.
Measuring the gaps
Using the rates from group_rates, each gap is a difference between two groups.
rates = group_rates(y_true, y_pred, group)
a, b = rates["A"], rates["B"]
equal_opportunity_gap = abs(a["tpr"] - b["tpr"])
equalized_odds_gap = max(abs(a["tpr"] - b["tpr"]), abs(a["fpr"] - b["fpr"]))Equalized odds uses the larger of the two differences. A model passes only if both TPR and FPR are close.
Worked example
Suppose a screening model produces these rates on a test set.
| Group | TPR | FPR |
|---|---|---|
| A | 0.82 | 0.10 |
| B | 0.66 | 0.09 |
The equal opportunity gap is |0.82 − 0.66| = 0.16. The FPR gap is only 0.01, so the equalized odds gap is also 0.16. The model is nearly fair on false positives and clearly unfair on true positives. Qualified people in group B are missed much more often.
Common errors
- Reading a small gap as a pass. A gap of 0.03 on 40 positive examples can be noise. Check confidence intervals before judging, as covered later in this tutorial.
- Ignoring undefined rates. If a group has no true positives in the test set, TPR is
nan. Report this instead of dropping the group. - Using hard predictions only. Both metrics depend on the decision threshold. A model can pass at one threshold and fail at another.
- Confusing the two labels. Equal opportunity is defined for the favorable outcome. If the favorable outcome is "not flagged," the relevant rate is the true negative rate, so check which label counts as the benefit.
- Trusting biased labels. These metrics treat
y_trueas correct. If labels record past biased decisions, equal error rates can preserve that bias.
Adjusting thresholds
If a model fails, one option is to use different thresholds per group. This is post-processing, and a later chapter covers it. The cost is that group-specific thresholds may be legally or ethically restricted in some settings. Satisfying equalized odds can also lower overall accuracy, and it may conflict with predictive parity, as a later chapter shows.
Exercise
A hiring model has TPR 0.74 for group A and 0.74 for group B, but FPR 0.20 for A and 0.08 for B. Does it satisfy equal opportunity? Does it satisfy equalized odds?
Show answer
It satisfies equal opportunity because the TPRs match. It does not satisfy equalized odds because the FPR gap is 0.12. Unqualified people in group A are wrongly selected much more often.
Exercise
Why can a model with a perfect classifier still fail demographic parity but pass equalized odds?
Show answer
A perfect classifier has TPR 1 and FPR 0 in every group, so equalized odds holds. If the groups have different base rates of positives, the selection rates differ, so demographic parity fails.