As machine learning systems are increasingly deployed to automate high-stakes decisions, it is critical to address algorithmic bias and ensure fairness.
Sources of Algorithmic Bias
Algorithmic bias arises at multiple pipeline stages:
Historical Bias: training data reflects existing systemic human prejudices.
Representation Bias: sample underrepresents demographics, raising error rates for minorities.
Measurement Bias: collected features are noisy, poor proxies of the target task.
Mathematical Definitions of Fairness
Fairness is defined mathematically, but different metrics are often mutually exclusive. Let be a sensitive attribute (e.g., race, gender), be the remaining features, be the true label, and be the model prediction.
1. Demographic Parity (Statistical Parity)
The likelihood of receiving a positive prediction is independent of the sensitive attribute:
2. Equal Opportunity
The true positive rate (recall) is equal across all demographic groups:
3. Predictive Parity
The precision (positive predictive value) is equal across all demographic groups:
These definitions are mathematically incompatible if the base rates differ between demographic groups, meaning a model cannot satisfy all of them simultaneously unless it makes perfect predictions.
Example: Evaluating Fairness
The following example calculates demographic parity difference between two groups:
Interactive Lab
import numpy as np
# sensitive attribute (0: Group A, 1: Group B)
sensitive = np.array([0, 0, 0, 0, 1, 1, 1, 1])
# model predictions
predictions = np.array([1, 0, 1, 0, 1, 1, 1, 0])
prob_a = np.mean(predictions[sensitive == 0])
prob_b = np.mean(predictions[sensitive == 1])
print(f"Positive selection rate Group A: {prob_a:.2f}")
print(f"Positive selection rate Group B: {prob_b:.2f}")
print(f"Demographic Parity Difference: {abs(prob_a - prob_b):.2f}")
Expected output
Positive selection rate Group A: 0.50
Positive selection rate Group B: 0.75
Demographic Parity Difference: 0.25
python
Interactive Lab
Evaluate Demographic Parity by calculating the difference in selection rates between two demographic groups. Adjust the predictions to see if you can reduce the difference to zero.
Step 1
Inspect the idea
Step 2
Edit the program
Step 3
Run and compare
Exercise
Test your understanding of mathematical fairness constraints:
Knowledge Check
Why is it mathematically impossible to satisfy demographic parity, equal opportunity, and predictive parity simultaneously in a non-trivial predictor?
Answer: Because unless the base rate of positive true labels is equal across all groups (P(Y=1|A=0) = P(Y=1|A=1)) or the classifier is perfectly accurate, these criteria mathematically conflict.
When base rates of true positive labels differ between groups, equal opportunity (equal recall) and predictive parity (equal precision) conflict unless predictions are perfectly accurate.
Why is it mathematically impossible to satisfy demographic parity, equal opportunity, and predictive parity simultaneously in a non-trivial predictor?