Sub topic 10
Intersectional groups
This chapter assumes you can compute per-group selection rate, TPR, and FPR (see the chapter on measuring outcomes per group). It also assumes you know basic pandas.
Why single attributes can hide harm
An intersectional group is defined by a combination of sensitive attributes, such as older women or young Black men. A model can look fair when you check sex alone and age alone, yet treat one combination badly. The marginal rates average over the other attribute, and that averaging can dilute a large gap in one cell.
A worked example
The code below simulates a model that selects 50% of every cell except women aged 40 and over, who are selected 20% of the time. It then compares the marginal gaps with the intersectional gap.
import numpy as np
import pandas as pd
rng = np.random.default_rng(0)
n = 4000
df = pd.DataFrame({
"sex": rng.choice(["F", "M"], n),
"age": rng.choice(["<40", "40+"], n),
})
p = np.where((df["sex"] == "F") & (df["age"] == "40+"), 0.2, 0.5)
df["selected"] = (rng.random(n) < p).astype(int)
for col in ["sex", "age"]:
rates = df.groupby(col)["selected"].mean()
print(col, "gap:", round(rates.max() - rates.min(), 3))
cells = df.groupby(["sex", "age"])["selected"].agg(rate="mean", n="size")
print(cells)
print("intersectional gap:", round(cells["rate"].max() - cells["rate"].min(), 3))The sex gap and the age gap are each about 0.15, because half of each marginal group sits in the affected cell. The intersectional gap is about 0.30. Checking only the marginals understates the problem by half.
You can reuse group_rates from earlier by building a combined label, for example df["sex"] + "/" + df["age"], and passing that as group. The same approach extends to TPR, FPR, and precision.
Costs of slicing finely
Each added attribute multiplies the number of cells. Two sex values, four age bands, and five ethnicity categories give 40 cells. Cells shrink quickly, and small cells produce noisy rates. A gap in a cell of 30 people may be chance.
- Report the count
nnext to every rate. - Attach a confidence interval to each rate, as covered in the chapter on small subgroups.
- Set a minimum cell size. Flag cells below it as "insufficient data" instead of dropping them silently.
- Choose which intersections to examine based on the harms and context you identified earlier, not by testing every combination. Testing hundreds of cells makes false alarms likely.
Common errors
- Checking only marginals and declaring the model fair.
- Ranking cells by rate without regard to cell size, so tiny cells dominate the "worst group" list.
- Dropping empty or tiny cells. Those people still receive predictions.
- Treating a fairness fix on one attribute as a fix for the intersection. Equalizing across sex alone can leave the 40+ women cell unchanged.
Exercise
A model has a selection-rate gap of 0.04 by sex and 0.05 by region. Your colleague concludes it passes a 0.10 tolerance. What should you check next, and why?
Show answer
Compute selection rates for each sex-by-region cell, along with cell sizes and confidence intervals. Marginal gaps average over the other attribute, so a large gap in one combination can be hidden. Judge a cell only if it has enough data to estimate its rate reliably.