Sub topic 7
Disaggregated evaluation across groups and conditions
This chapter assumes you can train and evaluate a binary classifier, know precision, recall, and false positive rate, and can read short Python scripts. It also assumes you have seen the model card sections from earlier chapters, especially the evaluation section. Here you will learn how to split evaluation results by group and by condition, and how to report them so a reader can act on them.
Why one number is not enough
An aggregate metric averages over everyone in the test set. If one subpopulation is small, it barely moves the average. The model can fail badly on that subpopulation while the headline number looks healthy.
The spine example makes this concrete. A model gets 4 of 6 predictions right, so overall accuracy is 0.67. Group a has accuracy 1.0 and group b has about 0.33. The overall figure describes neither group.
Disaggregated evaluation means computing the same metrics separately for each slice of the evaluation data. The 2019 paper "Model Cards for Model Reporting" asks for this explicitly. It calls for results broken down by individual factors and by their intersections, such as skin tone crossed with gender.
Groups versus conditions
A slice can be defined in two ways, and a card should cover both.
- Groups are sets of people or entities. Examples are age bands, dialects, regions, customer tiers, and demographic categories where it is lawful and appropriate to use them.
- Conditions are properties of the input or the environment. Examples are image brightness, audio background noise, text length, language, device type, and sensor model.
Conditions matter even when no people are involved. The support-ticket classifier from earlier chapters has a limitation on tickets shorter than 5 words. That is a condition, and you can only state it with evidence if you evaluated by ticket length.
Choosing which slices to report
Pick slices from three sources:
- The intended use. If the card says the model serves customers in several countries, evaluate per country.
- Known failure modes. Past incidents, error analysis, and domain experts point to slices that deserve a row.
- Harm analysis. Where errors cause unequal harm, slice by the attributes tied to that harm.
Record why you chose each slice. A reader who sees only three slices should be able to tell whether others were considered and dropped, or never considered.
Choosing metrics per slice
Accuracy alone can hide the kind of error. Report error rates that map to real costs.
| Metric | What it answers | When it matters most |
|---|---|---|
| Accuracy | How often is the prediction right? | Balanced classes, symmetric costs |
| False negative rate (FNR) | How many true positives are missed? | Missing a case is costly, such as fraud or disease screening |
| False positive rate (FPR) | How many negatives are wrongly flagged? | A false alarm is costly, such as account lockouts |
| Precision | Of the flagged items, how many are right? | Flags trigger expensive human review |
| Positive rate | How often does the model predict the positive class? | Comparing outcomes across groups |
Comparing FPR across groups corresponds to an equal-false-positive-rate view of fairness. Comparing FNR corresponds to equal opportunity. These criteria are generally not satisfiable together when base rates differ between groups. The card does not need to resolve that. It needs to report the numbers and say which error matters for the use case.
The evaluation workflow
Computing per-slice metrics with uncertainty
A per-slice number based on 12 examples is much less reliable than one based on 12,000. Always report the slice size n, and attach a confidence interval. The Wilson score interval behaves well for proportions with small samples, unlike the simple normal approximation, which can produce bounds below 0 or above 1.
The script below computes a confusion matrix per slice and then accuracy, FNR, FPR, and a Wilson interval for accuracy. It runs as shown with the standard library only.
from collections import defaultdict
from math import sqrt
def wilson_interval(successes, n, z=1.96):
if n == 0:
return (0.0, 1.0)
p = successes / n
denom = 1 + z**2 / n
center = (p + z**2 / (2 * n)) / denom
margin = z * sqrt(p * (1 - p) / n + z**2 / (4 * n**2)) / denom
return (max(0.0, center - margin), min(1.0, center + margin))
def rate(numerator, denominator):
return numerator / denominator if denominator else None
def disaggregate(y_true, y_pred, slices):
counts = defaultdict(lambda: {"tp": 0, "fp": 0, "fn": 0, "tn": 0})
for truth, pred, name in zip(y_true, y_pred, slices):
if truth == 1:
key = "tp" if pred == 1 else "fn"
else:
key = "fp" if pred == 1 else "tn"
counts[name][key] += 1
results = {}
for name, c in counts.items():
n = sum(c.values())
correct = c["tp"] + c["tn"]
low, high = wilson_interval(correct, n)
results[name] = {
"n": n,
"accuracy": correct / n,
"ci_low": low,
"ci_high": high,
"fnr": rate(c["fn"], c["tp"] + c["fn"]),
"fpr": rate(c["fp"], c["fp"] + c["tn"]),
}
return results
def fmt(value):
return "n/a" if value is None else f"{value:.2f}"
y_true = [1, 0, 1, 1, 0, 0]
y_pred = [1, 0, 1, 1, 1, 1]
slices = ["a", "a", "a", "b", "b", "b"]
print("| slice | n | accuracy | 95% CI | FNR | FPR |")
print("| --- | --- | --- | --- | --- | --- |")
for name, r in sorted(disaggregate(y_true, y_pred, slices).items()):
interval = f"{fmt(r['ci_low'])}-{fmt(r['ci_high'])}"
print(
f"| {name} | {r['n']} | {fmt(r['accuracy'])} | {interval} "
f"| {fmt(r['fnr'])} | {fmt(r['fpr'])} |"
)The output is a Markdown table you can paste into the card. With this toy data, group a has accuracy 1.00 and group b has 0.33. Group b also has an FPR of 1.00, because both of its negative examples were flagged. The intervals are wide, roughly 0.44 to 1.00 for a and 0.06 to 0.79 for b, because each slice has only three examples. The honest reading is "there is a warning sign, and the sample is too small to be sure." A card should say exactly that.
The rate helper returns None when a slice has no positives or no negatives. Printing n/a is correct in that case. Reporting 0.0 would claim a perfect result that was never measured.
Intersectional slices
Looking at each factor alone can miss problems that appear only in combinations. A speech model may work acceptably for each accent alone and for each noise level alone, yet fail for one accent in noisy conditions.
Intersections multiply the number of slices, and each slice gets fewer examples. With 4 values for one factor and 5 for another you have 20 cells. If the test set has 2,000 examples, many cells will hold fewer than 30.
Practical approaches:
- Report single-factor slices for everything, and intersections only where there is a reason to expect an interaction or where the cell is large enough to be meaningful.
- Set a minimum cell size, for example 30, and list smaller cells as "not reported, n too small" instead of dropping them silently.
- Build targeted test sets for important intersections instead of relying on random samples, which under-represent rare combinations.
Where slice labels come from
Slice labels are often the hardest part.
- Self-reported or collected attributes are the most reliable, but collecting them may be restricted by privacy law or by user trust. Follow your organization's legal guidance.
- Inferred attributes, such as a classifier guessing gender from a photo, introduce their own errors and can be inappropriate. If you use them, say so in the card and state the labeler's known accuracy.
- Proxy attributes, such as postal code standing in for income, are imperfect. Name the proxy and its limits.
- Condition labels such as text length or image brightness can usually be computed directly from the input.
Keep slice labels in the evaluation dataset only. They should not become model inputs unless that is a deliberate, reviewed decision.
Reading the gaps
Compare each slice against the overall result and against the best-performing slice. Two quantities help:
- Gap: the difference in a metric between a slice and a reference, such as the overall value or the best slice.
- Ratio: the slice value divided by the reference. This is useful for error rates, where a move from 1% to 3% is a threefold increase even though the gap looks small.
Whether a gap is acceptable is a product and risk decision, not a statistical one. The card should state the numbers and the team's judgment, not only the numbers.
Writing the section in the card
A good disaggregated results section has:
- The list of slices, with the reason each was chosen.
- A table with
n, the metrics, and intervals for every slice, including slices that look bad. - The overall result alongside, so the reader can see what the average hides.
- A short list of findings in plain language, for example "False positive rate is 0.12 on tickets under 5 words versus 0.04 overall."
- A statement of what was not evaluated.
Findings should flow into the limitations section. If a slice performs poorly, the limitation entry should say so, and the out-of-scope statement may need to exclude it.
Common errors
| Error | Why it hurts | Fix |
|---|---|---|
| Reporting only overall metrics | Hides weak slices | Add a per-slice table |
| Omitting `n` and intervals | Readers over-trust small slices | Report both for every slice |
| Reporting only slices where the model does well | Misleads readers | Fix slices before looking at results |
| Using the training distribution for slice sizes | Slice results do not match deployment | Build evaluation data that reflects the intended use |
| Tuning the model on the slice test set | Slice scores become optimistic | Keep a held-out set and tune on a separate validation set |
| Treating "no gap found" as "no bias" | Absence of evidence in tested slices only | State which slices were tested and which were not |
Summary
Disaggregated evaluation computes the same metrics for each group and condition, with sample sizes and uncertainty. Choose slices from the intended use, known failure modes, and harm analysis. Pick error rates that match the cost of mistakes. Keep intersections to those you can support with data, and say plainly what was not measured. The resulting table and findings feed directly into the limitations section of the card.
Exercise
A model card for a spoken-command recognizer reports overall accuracy of 0.94. A per-slice table shows the quiet-room slice at 0.96 with n = 4,000, and the car-noise slice at 0.71 with n = 18. Give two reasons the car-noise result should not be read as a precise measurement, and say what you would write in the card.
Show answer
First, n = 18 is small, so the 95% confidence interval around 0.71 is very wide (roughly 0.49 to 0.87 by the Wilson method), and the true accuracy could be considerably better or worse. Second, the car-noise slice contributes almost nothing to the overall 0.94, so the overall number says nothing about it. In the card, report the slice with its n and interval, flag it as low confidence, list car noise as a known weak condition in the limitations section, and either collect more car-noise data or mark that condition as not yet validated for the intended use.