Sub topic 3
Uncertainty, Subgroups, and Fairness Audits
Assume you know binary classification, confusion matrices, precision, recall, false positive rate, train/test splits, and basic Python with NumPy and scikit-learn. A fairness gap is an estimate, not automatically a fact about the population.
Uncertainty and small subgroups
A rate from a small group can change greatly when one prediction changes. Report each group’s sample size and an uncertainty interval, such as a bootstrap confidence interval. Treat a large-looking gap with a small sample cautiously. Also investigate missing data and groups that the model or dataset does not represent.
Intersectional groups
An intersectional group combines attributes, such as age and gender. A model can appear fair when measuring each attribute separately while harming a combined subgroup. Check enough combinations to reveal important risks, but avoid creating extremely small groups that cannot support reliable conclusions.
Individual and counterfactual fairness
Group metrics compare distributions. Individual fairness asks whether similar people receive similar treatment. Counterfactual fairness asks whether the result would change if a person’s sensitive attribute changed while other relevant facts stayed fixed. These ideas require a definition of “similar” and a defensible causal model. They cannot be proved from group rates alone.
Running a fairness audit
Use the same held-out test set for all groups. Record:
- group definitions, sample sizes, and missing-value handling
- selection rate, true positive rate, false positive rate, precision, and overall performance
- uncertainty intervals and practically important thresholds
- deployment context, possible harms, and affected stakeholders
Repeat the analysis for intersectional groups and compare results with the previous model version.
Assessment with Fairlearn
Fairlearn’s MetricFrame calculates metrics by group and summarizes differences. The sensitive feature is used for assessment; it does not have to be included as a model feature.
import numpy as np
from fairlearn.metrics import MetricFrame, selection_rate
from sklearn.metrics import accuracy_score, recall_score
y_true = np.array([1, 1, 0, 0, 1, 0, 1, 0])
y_pred = np.array([1, 0, 0, 1, 1, 0, 0, 0])
group = np.array(["A", "A", "A", "A", "B", "B", "B", "B"])
frame = MetricFrame(
metrics={"accuracy": accuracy_score, "recall": recall_score,
"selection_rate": selection_rate},
y_true=y_true, y_pred=y_pred, sensitive_features=group,
)
print(frame.by_group)
print(frame.difference())Mitigation and governance
Pre-processing changes data, in-processing changes training, and post-processing changes decisions or thresholds. Each can reduce one gap while harming accuracy, calibration, privacy, or another group. Select a criterion based on the harm and deployment context, then re-audit.
Document the metric definitions, data version, model version, uncertainty method, decisions, owners, and review date. Require review when data, thresholds, or deployment conditions change.
Exercise
Why should a large fairness gap from a group of five people be treated cautiously?
Show answer
Its estimate has high sampling uncertainty, so the observed gap may not represent the wider population.