Bias in machine learning (ML) refers to unfair discrimination in the outcomes produced by an algorithm for certain disadvantaged groups. Most of the time, this problem comes from the data used to train these algorithms, producing models that inadvertently encode pre-existing societal biases and prejudices.
Although different methods are being developed and applied to mitigate this problem during the different stages of an AI model's development, new questions have arisen. How can we measure the effectiveness of bias mitigation methods? And how can we calculate the method that presents the trade-off between fairness and accuracy in machine learning models?
In this blog, we will explore the fairness-accuracy trade-off analysis for classification models. This is similar in nature to a previous blog, Machine Learning Classification Models: Exploring the Fairness-Accuracy Trade-Off. However, the main difference is that this new approach allows us to categorise and benchmark bias mitigator models by measuring their effectiveness and comparing them with a baseline.
We will observe this with a pertinent case study.
Various methods have been developed to mitigate bias in ML models. However, improvements in fairness often come at the expense of reduced model accuracy. This is known as the trade-off between accuracy and fairness for ML models.
Taking this concept into account while also taking into consideration the diversity of mitigators, Hort et. al. presented an interesting approach, named Fairea, to benchmark bias mitigation methods and determine which ones present a better fairness-accuracy trade-off.
The core of this approach is the use of a model behaviour mutation method to create a baseline that can be used to compare quantitatively the fairness-accuracy trade-off for different bias mitigation algorithms and then evaluate their effectiveness in the given scenario.
To perform this analysis, the approach consists of three separate steps:
We will detail every stage in this blog post.
To put everything into practice, we will perform a case study by following the different stages of the Fairea approach, using them to perform a fairness-accuracy analysis and determine the most effective model.
For the computational implementation, we will use a Python environment with the following packages:
We start with our implementation. First, we import the required packages:
For our analysis, we will use the well-known “Adult dataset” from the UCI Machine Learning Repository, a publicly available dataset containing information about the age, education, marital status, race and gender of individuals from the United States. The objective is to predict whether an individual's income will be above or below $50K per year. The protected attribute we will use in this instance is the “Sex” feature.
This dataset can be easily imported and downloaded from the holisticai package by running the following lines:
Next, we preprocess and format the data. This can be achieved using the following function and running:
Now that we have our dataset and protected groups, we can start with the Fairea pipeline.
The first step involves a baseline construction. This is done by fitting a simple model which serves as a baseline, before the outputs are mutated to collect a set of trade-off points that will be used later to determine the mitigation regions for the model comparison. This mutation is achieved by copying the predictions and then replacing small sets with the same label. The following image gives more details of this procedure:
Table 1. Example of mutation procedure. Inspired from here.
This is done by running the following code:
Once the baseline has been created, the approach categorises the mitigator models into five regions that represent the effectiveness of the bias mitigation. These regions are:
The following figure shows how the mitigation regions are distributed:
Taking this into account, we will train our initial model next. But first, we will apply some mitigation methods. For this, we use the Correlation Remover and the Calibrated Equalized Odds methods which fall into the categories of preprocessing and postprocessing strategies respectively. We will also measure the accuracy of the models and the statistical parity as the accuracy and fairness metrics respectively.
We will do this by running the following code:
If we plot the methods and the baseline we will obtain the following graph:
To perform a better analysis, we will normalise the results and the graph:
Now, we will classify the mitigators into the mitigation regions:
For this particular case, we can see that both methods fall into the good trade-off region. This means that in, both methods, the bias has been reduced but the accuracy has also decreased.
After the mitigators have been categorised, the effectiveness of the methods is measured. Given that the win-win, lose-lose, inverted trade-off and the poor trade-off regions provide clear signals about how the mitigator performs, this measurement is focused on the mitigators that fall into the good trade-off region.
This is achieved by calculating the area that results by projecting a horizontal and a vertical line from the mitigator position to the trade-off points of the baseline. This area represents the strength of the fairness-accuracy trade-off. Therefore, the larger the area is, the better the fairness-accuracy trade-off.
To calculate this area for our case, we use the following code:
As we can see, the model that presents a better trade-off is the Correlation Remover method, since it presents a larger area in comparison with the Calibrated Equalized odds method.
During this tutorial, we have seen how to measure the effectiveness of bias mitigator strategies by following the Fairea approach, which allows the categorisation of models by comparing the fairness and accuracy with respect to a baseline. Consequently, after applying this methodology in a study case with the Adult dataset, we observe that the Correlation Remover and the Calibrated Equalized odds methods present a good fairness-accuracy trade-off. Furthermore, after measuring the effectiveness of both models through the trade-off strength calculation, represented with the area between the mitigator and the baseline, we found that the Correlation remover strategy presents a better fairness-accuracy trade-off.
For more detail on the presented approach, we recommend reading the original publication on the Fariea approach.
A complete implementation of this code can also be found here.
DISCLAIMER: This blog article is for informational purposes only. This blog article is not intended to, and does not, provide legal advice or a legal opinion. It is not a do-it-yourself guide to resolving legal issues or handling litigation. This blog article is not a substitute for experienced legal counsel and does not provide legal advice regarding any situation or employer.
Schedule a call with one of our experts