Intermediate level · Module 5: Bias Mitigation Strategies · Lesson 2 of 3
In-processing and Post-processing with Fairlearn
Learners apply Fairlearn's ExponentiatedGradient (training under a fairness constraint) and ThresholdOptimizer (group-aware decision thresholds), and understand when each is appropriate.
In this lesson you will
- Train a model under a fairness constraint with ExponentiatedGradient
- Adjust decision thresholds with ThresholdOptimizer
Key concepts
ExponentiatedGradientDemographicParity / EqualizedOdds constraintsThresholdOptimizergroup-specific thresholdssensitive features at prediction time
The lesson
In-processing changes how the model is trained. Fairlearn's ExponentiatedGradient wraps a scikit-learn estimator and a constraint such as DemographicParity() or EqualizedOdds(), and searches for a model that meets the constraint as closely as possible while staying accurate.
Post-processing keeps the trained model and changes how its scores become decisions. Fairlearn's ThresholdOptimizer chooses group-specific thresholds to satisfy a constraint. It needs the sensitive feature at prediction time, which may not be allowed or acceptable in some contexts, and this must be checked.
Each method changes who is selected. Always ask who gains and who loses, and confirm that the change is consistent with the organisation's policy and with applicable law.
Step by step
- Fit ExponentiatedGradient(LogisticRegression(max_iter=1000), constraints=EqualizedOdds()) with sensitive_features passed to fit().
- Fit ThresholdOptimizer(estimator=baseline, constraints='equalized_odds', prefit=True, predict_method='predict_proba').
- Compute the MetricFrame for both and add them to the before/after table.
- List who would gain and who would lose a place under each method.
Practice activity
Compare the baseline, reweighted, ExponentiatedGradient and ThresholdOptimizer models in one table.
Expected result: A four-row comparison with correct metrics and a clear description of who is affected by each change.
Check your understanding
-
What does ThresholdOptimizer need at prediction time?
Show answer
The sensitive feature for each person.
-
What does ExponentiatedGradient change?
Show answer
The training process, so that the model meets a fairness constraint as closely as possible.
Further learning
Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.