Sub topic 2
Demographic Parity
Assume you know binary classification, confusion matrices, precision, recall, false positive rate, and train/test evaluation. Fairness criteria compare a model’s outcomes across groups, such as groups defined by a protected attribute.
Demographic parity
Demographic parity requires equal selection rates:
\[ P(\hat{Y}=1 \mid A=a) = P(\hat{Y}=1 \mid A=b) \]
Here, \(\hat{Y}\) is the prediction and \(A\) is the group. For example, if 40% of group A receives a positive prediction and 60% of group B does, the demographic parity gap is 0.20.
import numpy as np
y_pred = np.array([1, 0, 1, 0, 1, 1, 0, 0])
group = np.array(["A", "A", "A", "A", "B", "B", "B", "B"])
for g in np.unique(group):
rate = y_pred[group == g].mean()
print(g, "selection rate:", rate)Demographic parity focuses on decisions, not whether those decisions are correct. It can therefore hide differences in error rates.
Equal opportunity and equalized odds
Equal opportunity requires equal true positive rates (TPRs):
\[ P(\hat{Y}=1 \mid Y=1,A=a) = P(\hat{Y}=1 \mid Y=1,A=b) \]
It asks whether qualified people are correctly selected at similar rates.
Equalized odds requires both equal TPRs and equal false positive rates (FPRs). It controls errors for people with positive and negative true labels:
| Criterion | Rates compared |
|---|---|
| Equal opportunity | TPR |
| Equalized odds | TPR and FPR |
Predictive parity and calibration by group
Predictive parity requires equal precision:
\[ P(Y=1 \mid \hat{Y}=1,A=a) = P(Y=1 \mid \hat{Y}=1,A=b) \]
Among people predicted positive, the same fraction should truly be positive.
Calibration by group applies to scores. A score of 0.7 should represent about a 70% positive outcome rate within every group. Calibration concerns probabilities, while predictive parity concerns a chosen decision threshold.
Why you cannot satisfy every criterion at once
These criteria measure different conditional probabilities. If groups have different base rates, a non-perfect model generally cannot satisfy demographic parity, equalized odds, and predictive parity simultaneously. Changing thresholds may improve one criterion while worsening another.
Choose a criterion from the harm you are trying to prevent, the legal and organizational context, and the consequences of errors.
Exercise
A model selects 30% of group A and 50% of group B. What is the demographic parity gap?
Show answer
The gap is 0.20, or 20 percentage points.