Sub topic 1
Why fairness assessment matters: harms and context
Prerequisites
This chapter assumes you know binary classification, confusion matrices, precision, recall, false positive rate, train/test splits, and basic Python with NumPy and scikit-learn.
Harms and context
A model is fair only in relation to a decision and its consequences. The same error can have different effects in different settings. A false negative in a medical screening system might delay treatment. A false positive in a fraud system might block a legitimate purchase.
Fairness assessment checks whether model errors or benefits are distributed differently across groups. A gap does not prove discrimination by itself. It signals that you need to inspect the data, labels, decision process, and deployment context.
Where bias enters the pipeline
Bias can enter before training, during modeling, or after deployment:
- Sampling bias: Some groups are underrepresented or missing from the training data.
- Measurement bias: Features measure the target differently across groups.
- Label bias: Historical decisions or human judgments become training labels.
- Model bias: The algorithm performs differently because patterns or sample sizes differ.
- Deployment bias: A model is used in a context different from the one assumed during development.
For example, a hiring model trained on past hiring decisions may reproduce past preferences. Removing a sensitive attribute does not necessarily solve this problem because other features can act as proxies.
Sensitive attributes and defining groups
A sensitive attribute is a characteristic such as race, gender, age, disability, or nationality that may be connected to unequal treatment or unequal impact. Use it for auditing when legally and ethically permitted. Do not assume that excluding it from model features makes fairness measurable or guaranteed.
Define groups before calculating metrics. Record category definitions, missing-value handling, reference groups, and whether people can belong to more than one category. Intersectional groups combine attributes, such as age and gender, and can reveal harms hidden by analyzing either attribute alone.
Measuring outcomes and errors per group
For each group, calculate the same quantities:
| Measure | Meaning |
|---|---|
| Selection rate | Fraction receiving a positive prediction |
| True positive rate | Fraction of actual positives predicted positive |
| False positive rate | Fraction of actual negatives predicted positive |
| Precision | Fraction of positive predictions that are correct |
import numpy as np
def group_rates(y_true, y_pred, group):
y_true, y_pred, group = map(np.asarray, (y_true, y_pred, group))
result = {}
for label in np.unique(group):
mask = group == label
actual, predicted = y_true[mask], y_pred[mask]
result[label] = {
"selection_rate": predicted.mean(),
"tpr": predicted[actual == 1].mean(),
"fpr": predicted[actual == 0].mean(),
"precision": actual[predicted == 1].mean(),
}
return result
y_true = [1, 1, 0, 0, 1, 0]
y_pred = [1, 0, 1, 0, 1, 0]
group = ["A", "A", "A", "B", "B", "B"]
print(group_rates(y_true, y_pred, group))Exercise
A model selects 60% of group A and 40% of group B. What should you conclude immediately?
Show answer
The selection rates differ by 20 percentage points, so investigate the cause and consequences. The gap alone does not establish whether the model is unfair.