Last Updated: 07/09/2020
The code can be accessed here.
In machine learning, a given algorithm is said to be fair, or to have fairness if its results are independent of some variables we consider to be sensitive and not related with it (f.e.: gender, ethnicity, sexual orientation, etc.).
A machine learning model makes predictions of an outcome for a particular instance. (Given an instance of a loan application, predict if the applicant will repay the loan.) The model makes these predictions based on a training dataset, where many other instances (other loan applications) and actual outcomes (whether they are repaid) are provided. Thus, a machine learning algorithm will attempt to find patterns, or generalizations, in the training dataset to use when a prediction for a new instance is needed. (For example, one pattern it might discover is "if a person has a salary > USD 40K and has outstanding debt < USD 5, they will repay the loan".) In many domains this technique, called supervised machine learning, has worked very well.
However, sometimes the patterns that are found may not be desirable or may even be illegal. For example, a loan repay model may determine that age plays a significant role in the prediction of repayment because the training dataset happened to have better repayment for one age group than for another. This raises two problems: 1) the training dataset may not be representative of the true population of people of all age groups, and 2) even if it is representative, it is illegal to base any decision on a applicant's age, regardless of whether this is a good prediction based on historical data.
Research about fairness in machine learning is a relatively recent topic. Most of the articles about it have been written in the last three years. Some of the most important facts in this topic are the following:
For this application, we showcase following 2 packages
This would help you navigate the documentation. The app is broadly divided into 2 parts. These parts support different packages.
The Aequitas module contains all the information for that package. The contents are as follow:
IBM's AIF360 module contains all the information for that module. The contents are as follow:
Aequitas is an open-source bias audit toolkit for data scientists, machine learning researchers, and policymakers to audit machine learning models for discrimination and bias, and to make informed and equitable decisions around developing and deploying predictive tools.
This package is model-based and checks whether the model trained is biased or not. The package requires a specific format for the report generation. The input CSV file should contain a ‘score' and ‘label_value' columns. The score is the model generated score. It can be either a class prediction or even class probability. The label_value is the ground truth values.
The COMPAS Recidivism Risk Score Data and Analysis: Data contains variables used by the COMPAS algorithm in scoring defendants, along with their outcomes within 2 years of the decision, for over 10,000 criminal defendants in Broward County, Florida. Below you can identify some (not all) columns within the dataset.
Looking into the dataset, the files contain complete loan data for all loans issued through the 2007-2015, including the current loan status (Current, Late, Fully Paid, etc.) and latest payment information. Additional features include credit scores, number of finance inquiries, address including zip codes, and state, and collections among others. There are 145 columns with information representing individual loan accounts. Each row is divided by an individual loan id and member id, of course, for the interest of privacy each member id has been removed from the dataset. Below you can identify some (not all) columns within the dataset.
‘Loan_status' is the target variable here. The meaning of other variables can be found here.
The aequitas package offers functionalities as a web-app as well as from command line to generate the report. The packages, not only creates a PDF document but also a .csv file with all the values. In the most simplest terms, the .csv//PDF can be thought of a large pivot table representing the data.
The report has a fixed input format. It requires:
Following is sample for the report format:
A sample report can be found here. The report can be mainly divided into 3 parts.
This tutorial heavily depends on metrics like accuracy, parity difference, equal odds difference, disparate impact, theil index, and other. So it's better to have a good understanding for the same. Let's look at them now. Refer to this wikipedia page for more information.
Ensure all protected groups have equal representation in the selected set. This criteria considers an attribute to have equal parity if every group is equally represented in the selected set. In simple terms, it tells about the data's distribution among the categories.
For example, consider the column ‘homeownership' from our Lending Club data. The available categories are [‘Any', ‘MORTGAGE', ‘RENT', ‘OTHER']. We see that there is unequal distribution of them in the data.
Ensure all protected groups are selected proportional to their percentage of the population. This criteria considers an attribute to have proportional parity if every group is represented proportionally to their share of the population. If your desired outcome is to intervene proportionally on people from all categories, then you care about this criteria
For example, the disparity for ‘Grade' is
Ensure all protected groups have the same false positive rates (as the reference group). This criteria considers an attribute to have False Positive parity if every group has the same False Positive Error Rate.
For example, the FPR for column ‘homeownership' is
This means that categories with ‘Mortgage' have 0.7 times the false positive rate as ‘Own' i.e. the model would predict positive class for ‘Own' more than the category ‘Mortgage'.
Ensure all protected groups have equally proportional false positives within the selected set (compared to the reference group). This criteria considers an attribute to have False Discovery Rate parity if every group has the same False Discovery Error Rate.
For example, again for homeownership, the FDR parity is
Ensure all protected groups have the same false negative rates (as the reference group). This criteria considers an attribute to have False Negative parity if every group has the same False Negative Error Rate.
For example, for the column ‘term period' the FNR parity is
At the end of the report, the relative values and the absolute values for the metrics are reported.
In this module we showcase how different people can read and/or analyze the report.
Let's start with a Data Scientist.
After reading the report, the data scientist would infer that the model is biased in many ways. Some of the possible scenarios to come up are as follows:
Solutions to this problem can be as follows:
1.Get more representative data. 2.Use stratify splitting to at least mitigate the proportional parity bias. 3.Assign instance weights or class weights to the different categories involved. 4.Have all the data on the same scale
Solutions to this problem can be addressed in following ways:
1.Experiment with different models like tree models, linear models or more try to add some form of non-linearity to the model thereby being able to capture the information. 2.Add high penalty for wrong classifications and reward. 3.Change the loss function. 4.Regularize the model by adding type I or type II penalty losses.
Now, let's consider a finance person. Clearly, she/he doesn't have knowledge of the underlying model and cannot effectively change the model. Some of the possible scenarios for her/him would be as follows:
This way, one can ‘reject opinion' and ‘remove prejudice' from the model manually.
Before we talk about dataset, it is important to know what can be considered as a protected variable.
Protected variable: An attribute that partitions a population into groups whose outcomes should have parity. Examples include race, gender, caste, and religion. Protected attributes are not universal, but are application specific.
For demonstration purposes, we are using 3 datasets:
This is German data after cleaning and binning.
The methods can be broadly classified into 3 groups:
These techniques are applied before any training happens. In simple words, we play around with the data to mitigate the bias if any.
For example,
These techniques focus on the classifier itself. They add a regularisation term to the objective function of the classifier.
For example,
These techniques are based on the predictions. These involve changing the predictions to make the classifier fairer.
For example,
We showcase following methods:
This tutorial heavily depends on metrics like accuracy, parity difference, equal odds difference, disparate impact, theil index, and other. So it's better to have a good understanding for the same. Let's look at them now. Refer to this wikipedia page for more information.
Accuracy It is the ratio of number of correct predictions to the total number of input samples.Mathematically, it is defined as accuracy = correct predictions / total predictions
Computed as the difference of the rate of favorable outcomes received by the unprivileged group to the privileged group. The ideal value of this metric is 0. Fairness for this metric is between -0.1 and 0.1
This metric is computed as the difference of true positive rates between the unprivileged and the privileged groups. The true positive rate is the ratio of true positives to the total number of actual positives for a given group. The ideal value is 0. A value of < 0 implies higher benefit for the privileged group and a value > 0 implies higher benefit for the unprivileged group. Fairness for this metric is between -0.1 and 0.1.
Computed as average difference of false positive rate (false positives / negatives) and true positive rate (true positives / positives) between unprivileged and privileged groups. The ideal value of this metric is 0. A value of < 0 implies higher benefit for the privileged group and a value > 0 implies higher benefit for the unprivileged group. Fairness for this metric is between -0.1 and 0.1.
Computed as the ratio of rate of favorable outcome for the unprivileged group to that of the privileged group. The ideal value of this metric is 1.0 A value < 1 implies higher benefit for the privileged group and a value >1 implies a higher benefit for the unprivileged group. Fairness for this metric is between 0.8 and 1.2.
Computed as the generalized entropy of benefit for all individuals in the dataset, with alpha = 1. It measures the inequality in benefit allocation for individuals. A value of 0 implies perfect fairness. Fairness is indicated by lower scores, higher scores are problematic
This is the comparison between various methods using German Credit dataset with Sex as the protecte variable. The train column is the original column (without any mitigation of bias) and other columns are the various mitigation methods as discussed.
Following are some of the conclusions: