Fairlearn
- Values: {
fairness
}
- Fairness type: { group fairness }
- Categories: { model-agnostic }
- Stage: { preprocessing in-processing post-processing }
- Repository: https://github.com/fairlearn/fairlearn
- Tasks: { classification regression }
- Input data: { tabular }
- Licence: MIT
- Languages: { Python }
- Frameworks: { scikit-learn }
- References:
The documentation of fairlearn
is excellent and provides a good introduction to the topic of fairness in AI.
It is emphasized that fairness algorithms are no plug-and-play technical solutions, but require serious thought about the context of the data and the problem at hand.
Fairness is a fundamentally sociotechnical challenge and cannot be solved with technical tools alone. They may be helpful for certain tasks such as assessing unfairness through various metrics, or to mitigate observed unfairness when training a model. Additionally, fairness has different definitions in different contexts and it may not be possible to represent it quantitatively at all. (source)
Fairlearn contains two main components:
- “Metrics for assessing which groups are negatively impacted by a model, and for comparing multiple models in terms of various fairness and accuracy metrics.”
- “Algorithms for mitigating unfairness in a variety of AI tasks and along a variety of fairness definitions.”
- Not all algorithms are applicable to all machine learning tasks.
- Not all algorithms support all fairness definitions
Fairlearn
contains two reduction algorithms that incorporate fairness constraints into a (binary) classification or regression problem by reducing the problem into a sequence of weighted classification or regression problems.
The only requirement of the fairlearn
implementation is that the base estimator has a fit
and predict
call, so for example all your typical sklearn
estimators are compatible.
This is applied in the
in-processing
stage.
Note that currently multi-class classification is not supported!
An interesting difference with a typical predict function is that sometimes randomized predictions are used:
Fairlearn mitigation algorithms largely follow the conventions of scikit-learn, meaning that they implement the fit method to train a model and the predict method to make predictions. However, in contrast with scikit-learn, Fairlearn algorithms can produce randomized predictors. Randomization of predictions is required to satisfy many definitions of fairness. Because of randomization, it is possible to get different outputs from the predictor’s predict method on identical data. For each of our algorithms, we provide explicit access to the probability distribution used for randomization. source
Fairlearn
also contains a
preprocessing
algorithm to remove correlation of non-sensitive features with sensitive features.
This addresses the potential issue that a machine learning model makes inferences based on sensitive features, even when these features are not explicitly included in the data, by instead using highly correlated features that were not considered to be sensitive on their own.
Fairlearn
also contains a
post-processing
algorithm that takes (possibly biased) model output and then fits a monotone transformation such that a chosen parity constraint is still satisfied.
All these methods are thus model-agnostic . Note that being model-agnostic does not necessarily imply that the methods are also post-processing , even though this generally does hold in the case of explainability .
Fairness definitions / Parity constraints
Generally speaking, the goal of the type of fairness that fairlearn
implements is to avoid harm.
There are various ways to implement this.
The fairlearn
package distinguishes and implements the following fairness constraints for group fairness:
Binary classification:
- DP - Demographic Parity: “the percentage of samples with label 1 should be equal across all groups”
- Note that this concerns the predicted label, not the true label.
- TPRP - True positive rate parity: sensitive features should not affect the true positive rate
- FPRP - False positive rate parity: sensitive features should not affect the false positive rate
- EO - Equalized odds: “satisfies both true positive rate parity and false positive rate parity”
- ERP - Error Rate Parity: “error rates should be the same across all groups”, which again is another way of saying that sensitive features should not affect error rates
Fairlearn
includes various possible relaxations for these constraints, as exact parity is often unrealistic.
Regression:
- BGL - Bounded Group Loss: the expected (regression) loss of each group must be below a chosen threshold