Sub topic 10
Intersectional groups
This chapter assumes you can compute per-group selection rates and error rates (see "Measuring outcomes and errors per group") and that you know the basic group criteria. It also assumes you are comfortable with pandas groupby. Here you will learn why checking one sensitive attribute at a time can miss unfairness, and how to measure groups defined by several attributes without fooling yourself.
What "intersectional" means
An intersectional group is defined by a combination of attributes. "Black women" is an example, as are "women over 60" and "disabled men under 25". The term comes from legal scholarship on discrimination that affects people in ways that neither race alone nor sex alone describes.
For an audit, the practical point is a mathematical one. A model can look fair on each attribute taken alone and still treat specific combinations very differently. Marginal fairness (fairness on each attribute separately) does not imply fairness on the combinations.
A worked example in which marginals hide a gap
Suppose a screening model has two binary attributes, sex (F, M) and race (X, Y). It selects people at these rates in each combination, with 200 people per cell:
| Row | race X | race Y |
|---|---|---|
| sex F | 0.50 | 0.30 |
| sex M | 0.30 | 0.50 |
Average over a row or a column and you get 0.40 every time. The demographic parity gap for sex is 0, and the gap for race is 0. The gap between the best and worst combination is 0.20.
The following code builds this data and audits it three ways. It also adds a Wilson score interval, which behaves better than the normal approximation when rates are near 0 or 1 or counts are small.
import numpy as np
import pandas as pd
cells = {
("F", "X"): (200, 0.50),
("F", "Y"): (200, 0.30),
("M", "X"): (200, 0.30),
("M", "Y"): (200, 0.50),
}
frames = []
for (sex, race), (n, rate) in cells.items():
k = round(n * rate)
pred = np.r_[np.ones(k, dtype=int), np.zeros(n - k, dtype=int)]
frames.append(pd.DataFrame({"sex": sex, "race": race, "y_pred": pred}))
df = pd.concat(frames, ignore_index=True)
def wilson(k, n, z=1.96):
"""95% Wilson score interval for a proportion k/n."""
p = k / n
denom = 1 + z**2 / n
centre = (p + z**2 / (2 * n)) / denom
half = z * np.sqrt(p * (1 - p) / n + z**2 / (4 * n**2)) / denom
return centre - half, centre + half
def audit(df, cols):
t = df.groupby(cols)["y_pred"].agg(n="size", k="sum")
t["selection_rate"] = t["k"] / t["n"]
bounds = [wilson(k, n) for k, n in zip(t["k"], t["n"])]
t["ci_low"] = [b[0] for b in bounds]
t["ci_high"] = [b[1] for b in bounds]
gap = t["selection_rate"].max() - t["selection_rate"].min()
return t.round(3), round(gap, 3)
for cols in (["sex"], ["race"], ["sex", "race"]):
table, gap = audit(df, cols)
print(f"Grouping by {cols}: max-min gap = {gap}")
print(table, end="\n\n")The sex and race audits print a gap of 0.0. The ["sex", "race"] audit prints a gap of 0.2, and the intervals for the two best cells (about 0.43 to 0.57) do not overlap those of the two worst cells (about 0.24 to 0.37). The gap is therefore not a sampling accident.
This example is built so the effects cancel exactly. Real data rarely cancels this neatly, but partial masking is common. A gap that is large in one cell gets diluted when that cell is pooled with larger, better-treated cells.
Why the problem gets hard quickly
The difficulty is not conceptual. It is counting. Each new attribute multiplies the number of cells, and the data in each cell shrinks.
| Attributes | Levels | Cells | Average cell size at 10,000 rows |
|---|---|---|---|
| sex | 2 | 2 | 5,000 |
| sex × race | 2 × 5 | 10 | 1,000 |
| sex × race × age band | 2 × 5 × 4 | 40 | 250 |
| sex × race × age band × disability | 2 × 5 × 4 × 3 | 120 | about 83 |
Averages also overstate the situation. Real populations are unbalanced, so some cells hold a handful of people while others hold thousands. Rates that depend on the positive class are worse. TPR is computed only over people with y_true == 1, so a cell with 80 rows and a 5% base rate gives a TPR from 4 people.
Two failure modes follow:
- Cells too small to measure. A cell with 4 positives yields a TPR that jumps by 0.25 when one person changes. Its interval spans most of [0, 1], and a point estimate alone is misleading.
- Spurious gaps from many comparisons. With 120 cells, some will look extreme by chance alone. The max-min gap is biased upward as the number of small cells grows, because the maximum and minimum of noisy estimates are noisier than the typical estimate.
Both failure modes push in opposite directions, and you have to guard against each of them. Ignoring small cells hides real harm. Over-reading them produces false alarms.
Handling small cells
Several practices help, and a sound audit usually combines them.
- Report counts with every rate. Show
n(and the positive count for TPR) next to each estimate. A reader should see at once that 0.60 came from 5 people. - Show intervals, not only point estimates. Wilson intervals, as above, or bootstrap intervals for rates that are not simple proportions.
- Set a minimum-support rule before you look. For example, flag any cell with fewer than 30 relevant rows (30 positives for TPR, 30 negatives for FPR) as "insufficient data" instead of reporting a gap. Pick the threshold from how precise the estimate must be, then record it.
- Compare each cell to a reference, not only to the other extreme. Comparing every cell to the overall rate (or to the best-supported group) uses all of the data and avoids relying on the single luckiest and unluckiest cells.
- Account for multiple comparisons. When you test many cells, adjust the threshold (for example, a Bonferroni or false discovery rate correction), or treat results as leads for investigation, not as conclusions.
- Collect more data where it is thin. If a combination matters for the deployment and you cannot measure it, the honest finding is "unmeasured", and the fix is targeted data collection.
Deciding which intersections to check
You cannot audit every possible combination, so choose deliberately. The following flow gives one workable order.
Good reasons to prioritize an intersection:
- Domain history. Prior audits, complaints, or legal frameworks point to specific combinations.
- Mechanism. A feature correlates with two attributes at once. A proxy such as postcode may encode race, and a job-gap feature may interact with sex and age.
- Input quality. A measurement tool may work worse for some combinations. Face analysis and skin tone with sex is the standard example.
- Stakeholder input. The people affected often know which combinations they worry about.
Fix the list of intersections before you look at results where possible. Choosing the worst-looking cells after the fact is a form of data dredging. If you do explore, label it as exploration and confirm any finding on held-out data.
Doing the same with Fairlearn
Fairlearn's MetricFrame accepts several sensitive features at once. Pass a DataFrame with multiple columns as sensitive_features, and by_group returns a result indexed by the combination of values. Its difference() and group_min() methods then work across the combinations. Use MetricFrame with a count metric alongside your rates so that cell sizes appear in the same table. If your version supports it, control_features lets you compute metrics within strata of a legitimate conditioning variable, which is a different task from intersecting attributes.
Interpreting results
A gap in a cell tells you where to look. It does not tell you why. Before concluding that the model is unfair to a combination, check the following:
- Base rates differ. If the true positive rate in the population differs by cell, demographic parity gaps and predictive parity gaps can coexist with accurate predictions. The chapter on why criteria conflict applies here at the level of cells.
- Label quality differs. If labels come from past human decisions, the cell may carry biased labels, and TPR against those labels is not a clean measure.
- The attribute is noisy. If the attribute is inferred or self-reported inconsistently, cell membership is uncertain, and so are the rates.
Also remember that the criteria you chose still apply. An intersectional audit does not introduce a new metric. It applies the same metric (selection rate, TPR, FPR, precision) to finer groups, and the same incompatibilities hold.
Common errors
- Reporting only the marginal audits and calling the model fair across "all" groups.
- Reporting a cell rate without its count or interval.
- Taking the max-min gap across 100+ cells as a headline number without correcting for noise.
- Choosing intersections after seeing which ones look bad, then presenting them as pre-planned.
- Dropping small cells silently so the table looks clean.
- Treating missing attribute values as one more category without checking who is missing.
Exercise
A model is audited on sex (2 levels), age band (4 levels), and ethnicity (6 levels) using 12,000 test rows. (a) How many intersectional cells exist, and what is the average cell size? (b) The sex-only and age-only selection-rate gaps are both below 0.02, but the sex × age gap is 0.15, and the smallest sex × age cell has 18 rows. What should you report, and what should you do before concluding the model is unfair to that cell?
Show answer
(a) There are 2 × 4 × 6 = 48 cells, so the average size is 12,000 / 48 = 250 rows. Real cells will vary around that average, and TPR needs positives, so the effective size for TPR is smaller. (b) Report that the marginal gaps are small but the intersectional gap is 0.15, which shows the marginal audits can hide a disparity. Report counts and intervals for every cell. If the 0.15 gap involves the 18-row cell, its interval is wide, so flag it as low-support and do not treat it as established. Check whether the gap persists in cells with adequate support, apply a multiple-comparison correction if you examined many cells, and plan more data collection or a larger evaluation set for the thin cell. Record the minimum-support rule and the comparisons you made.