Sub topic 14
Mitigation: pre-, in-, and post-processing
This chapter assumes you can compute per-group selection rate, TPR, FPR, and precision, and that you have run an audit that found a gap you want to reduce. You should also know how to train a scikit-learn classifier and split data into train and test sets.
Three places to intervene
Mitigation changes the model pipeline so that a measured gap shrinks. You can intervene at three points:
- Pre-processing changes the training data before the model sees it.
- In-processing changes the training procedure so the model learns under a fairness constraint or penalty.
- Post-processing leaves the trained model alone and changes its outputs, usually by adjusting decision thresholds per group.
Pre-processing
Pre-processing fixes the data. Common techniques are reweighting examples so each combination of group and label carries balanced influence, resampling underrepresented groups, and relabeling examples you believe are mislabeled. These methods work with any model, because the model code does not change. The cost is that the link between your change and the final metric is indirect. A reweighted dataset can still produce a model with a large equalized-odds gap, so you must re-measure.
In-processing
In-processing builds the fairness goal into learning. Examples include adding a penalty term for the gap between groups, or solving a constrained optimization problem. This usually gives the best trade-off between accuracy and the chosen criterion, because the model can adapt its internal representation. The costs are that you need a training method that supports the constraint, and that training is more complex and slower. You also cannot apply it to a model you did not train, such as a vendor model.
Post-processing
Post-processing needs only the model's scores and the sensitive attribute. Fairlearn's ThresholdOptimizer learns group-specific thresholds that reduce an equalized-odds or demographic-parity gap.
from sklearn.linear_model import LogisticRegression
from fairlearn.postprocessing import ThresholdOptimizer
base = LogisticRegression(max_iter=1000)
mitigator = ThresholdOptimizer(
estimator=base,
constraints="equalized_odds",
predict_method="predict_proba",
)
mitigator.fit(X_train, y_train, sensitive_features=group_train)
y_pred_adj = mitigator.predict(X_test, sensitive_features=group_test, random_state=0)Here ThresholdOptimizer fits the base estimator and then learns the thresholds. The random_state matters because the optimizer may randomize decisions near a threshold to hit the target rates exactly. Identical applicants can therefore receive different outcomes, which is a problem in some settings.
Comparing the options
| Stage | Needs to retrain the model | Needs the sensitive attribute at prediction time | Main trade-off |
|---|---|---|---|
| Pre-processing | Yes | No | Indirect effect on the metric |
| In-processing | Yes | Usually no | Complex training, needs a supporting algorithm |
| Post-processing | No | Yes | Group-dependent decisions, possible randomization |
The last column matters in practice. If law or policy forbids using the sensitive attribute when making a decision, post-processing with group thresholds may not be allowed, even though it is the simplest method.
After mitigating: re-run the audit
Mitigation is not finished until you re-measure on held-out data. Check three things:
- The target gap shrank, and the confidence interval on the new gap is narrow enough to trust the change.
- Overall accuracy and other group metrics did not degrade beyond what stakeholders accepted. Because criteria conflict, reducing one gap can widen another, such as predictive parity.
- Intersectional and small subgroups did not get worse while the main groups improved.
Exercise
A lender uses a vendor's scoring model that you cannot retrain, and policy allows using group membership to set thresholds. Which mitigation stage fits best, and what should you check afterward?
Show answer
Post-processing, such as group-specific thresholds with ThresholdOptimizer, because it needs only the scores and the sensitive attribute. Afterward, re-run the audit on held-out data to confirm the target gap shrank, that accuracy and other criteria such as predictive parity did not degrade unacceptably, and that small and intersectional subgroups did not get worse.