Page19/22
ML Ethics & Fairness · Page 1 of 1
Bias in Machine Learning
ML Ethics & Fairness
Types of Bias
1. Data Bias
Training data doesn't represent the real population.
- Example: Loan approval model trained only on white applicants → Biased against minorities
- Fix: Ensure balanced representation in training data
2. Algorithmic Bias
The algorithm itself is biased.
- Example: Using ZIP code as feature (proxy for race) → Redlining
- Fix: Remove protected attributes (race, gender, age)
3. Historical Bias
If the past was unfair, the model learns unfairness.
- Example: Hiring model trained on previous unfair hiring decisions
- Fix: Clean the labels or retrain with fair labels
Fairness Definitions
Statistical Parity
Equal positive prediction rate across groups.
P(predict=1 | Group A) = P(predict=1 | Group B)
Equalized Odds
Equal True Positive Rate and False Positive Rate.
- Everyone has equal chance of being caught (TP rate)
- Everyone has equal false alarm rate (FP rate)
Demographic Parity
Prediction should be independent of protected attribute.
Detecting Bias
from sklearn.metrics import confusion_matrix
# Check metrics by group
for group in ['Male', 'Female']:
y_true_group = y_true[gender == group]
y_pred_group = y_pred[gender == group]
acc = accuracy_score(y_true_group, y_pred_group)
# If accuracy_male >> accuracy_female, bias detected!
Mitigating Bias
Pre-processing
Clean training data before training:
- Remove protected attributes
- Balance representation
- Audit for proxy variables
In-processing
Modify algorithm during training:
- Fairness constraints in objective function
- Different regularization by group
Post-processing
Adjust predictions after training:
- Change threshold by group
- Example: If females have lower approval rate, lower threshold for females
Real-World Consequences
COMPAS Recidivism Score
Algorithm used to predict prisoner reoffending showed bias against Black Americans.
- False positive rate for Black defendants: 45%
- False positive rate for white defendants: 23%
Amazon Hiring ML
Trained on historical data where males were hired more.
- Model learned to prefer male applicants
- System scrapped after discovery
Loan Approval
Denying loans based on ZIP code (proxy for race) = Illegal (Redlining)
main.py
Loading...
OUTPUT
▶Click "Run Code" to execute…