Bias Mitigation Strategies: Pre-processing, In-processing, and Post-processing
Learners will apply reweighing (pre-processing), add a fairness constraint to training (in-processing), and calibrate decision thresholds per group (post-processing), comparing trade-offs.
Three Stages of Bias Mitigation
Bias mitigation strategies fall into three categories based on where in the ML pipeline they intervene. Pre-processing methods modify the training data before any model is trained. In-processing methods modify the learning algorithm itself to enforce fairness during training. Post-processing methods adjust the model's outputs after training without changing the model. Each approach has different trade-offs in accuracy, flexibility, and computational cost.
Pre-processing: Reweighing
Reweighing assigns different sample weights to training examples so that the weighted distribution is fair with respect to the protected attribute. Examples from under-represented (label, group) combinations receive higher weight; over-represented combinations receive lower weight. The model is then trained with these weights using the sample_weight parameter, which most scikit-learn estimators accept. No changes to the algorithm are needed.
from fairlearn.preprocessing import CorrelationRemover
import numpy as np
import pandas as pd
from sklearn.linear_model import LogisticRegression
from sklearn.preprocessing import StandardScaler
# Reweighing: compute weights to balance (group, label) combinations
def compute_reweighing_weights(y, sensitive):
n = len(y)
weights = np.ones(n)
for label in np.unique(y):
for group in np.unique(sensitive):
mask = (y == label) & (sensitive == group)
expected = (y == label).mean() * (sensitive == group).mean()
actual = mask.mean()
if actual > 0:
weights[mask] = expected / actual
return weights
# Usage: model.fit(X_train, y_train, sample_weight=weights)All lessons in this course
- SHAP Values: Global and Local Feature Importance
- LIME: Local Interpretable Model-Agnostic Explanations
- Fairness Metrics: Demographic Parity and Equal Opportunity
- Bias Mitigation Strategies: Pre-processing, In-processing, and Post-processing