Sub topic 7
Disaggregated Evaluation Across Groups and Conditions
Assume you know how to split data into training, validation, and test sets, and how to calculate accuracy, precision, and recall. This chapter focuses on evaluating a trained model separately across relevant groups and operating conditions.
Why aggregate metrics are not enough
An aggregate metric combines all test examples into one number. That number can hide important differences. A classifier might report 91% accuracy overall while performing much worse for one language, region, age group, device type, or input length.
Disaggregated evaluation, also called slice-based evaluation, calculates metrics for defined subsets of the test data. A slice is a group or condition, such as:
- Customer region
- Language
- Product category
- Image lighting condition
- Text length
- Device type
- Class label
- Intersection of several attributes
The goal is not to prove that every group has identical results. The goal is to reveal where performance changes so that users can make informed decisions.
Define useful slices
Choose slices based on how the model will be used and where errors could cause harm. A slice should have a clear definition that another person can reproduce.
For example, “short ticket” should have a threshold:
- Short: fewer than 5 words
- Medium: 5 to 20 words
- Long: more than 20 words
Record how each slice was created, including the source of the grouping field, its allowed values, and what happens when the value is missing.
Avoid creating dozens of slices without a reason. Small slices can produce unstable metrics, and testing many slices increases the chance of finding a random difference. Start with groups connected to the intended use, known data gaps, and plausible sources of unequal error.
Report metrics per slice
Use metrics that match the model’s task and the cost of its errors. For a classifier, report accuracy alongside class-sensitive metrics such as precision, recall, and macro F1. For an imbalanced task, accuracy alone can be especially misleading.
The following example computes accuracy by group:
from collections import defaultdict
def accuracy_by_group(y_true, y_pred, groups):
correct = defaultdict(int)
total = defaultdict(int)
for truth, prediction, group in zip(y_true, y_pred, groups):
total[group] += 1
correct[group] += int(truth == prediction)
return {
group: correct[group] / total[group]
for group in total
}
y_true = [1, 0, 1, 1, 0, 0]
y_pred = [1, 0, 1, 1, 1, 1]
groups = ["a", "a", "a", "b", "b", "b"]
print(accuracy_by_group(y_true, y_pred, groups))
# {'a': 1.0, 'b': 0.3333333333333333}The overall accuracy is 4 out of 6, or about 0.67. That summary hides a perfect score for group a and a score of about 0.33 for group b.
A model card should show the sample count for every slice. It should also state whether metrics are estimated from an independent test set.
| Slice | Test examples | Accuracy | Recall | Notes |
|---|---|---|---|---|
| Group A | 3,000 | 0.96 | 0.94 | Stable estimate |
| Group B | 180 | 0.82 | 0.71 | Wider uncertainty |
| Short input | 95 | 0.68 | 0.61 | Consider rejecting or reviewing |
Interpret differences carefully
A performance gap is a signal for investigation, not an explanation by itself. A difference might result from:
- Different label quality across groups
- Too few examples in a slice
- Distribution shift between test and production data
- Different class frequencies
- A feature that works well in one condition but poorly in another
Include uncertainty when possible. Confidence intervals or bootstrap intervals show whether a small observed gap could be sampling noise. Do not treat a threshold such as “less than five percentage points” as a universal fairness rule. The acceptable gap depends on the task, risks, users, and applicable requirements.
Intersectional slices can reveal problems hidden by single-variable analysis. For example, performance for all non-English tickets might look acceptable, while performance for short Spanish tickets is poor. Use intersectional analysis selectively because sample sizes shrink as more conditions are combined.
Add findings to the model card
A useful model card records the slice definitions, sample counts, metrics, uncertainty, and known causes or hypotheses. It should state whether a gap blocks deployment, requires human review, or leads to a monitoring requirement.
When the model, data, threshold, or intended use changes, rerun the relevant disaggregated evaluation. Keep prior results with the model version so readers can distinguish a real improvement from a change in test composition.
Exercise
A model has 95% overall accuracy. Group A has 98% accuracy on 900 examples, while Group B has 80% accuracy on 20 examples. What should the model card report?
Show answer
It should report the group-specific metrics and sample counts, explain that the Group B estimate is uncertain because the sample is small, and investigate whether more representative test data or additional safeguards are needed.