EqualityML
Equality AI (EAI) is a public-benefit corporation dedicated to providing developers with evidence-based tools to end algorithmic bias. Our tools are built by developers for developers. So, we know that developers want their models to be fair, but we also understand that bias is difficult and intimidating.
The EAI EqualityML
repository provides tools and guidance on how to include fairness and bias mitigation methods to model fitting so as to safeguard the people on the receiving end of our models from bias.
If you like what we're doing, give us a :star: and join our EAI Manifesto!!
We have extented
EqualityML
to include other aspects of Responsible AI (see full framework Figure 1.) and collaboration features to create our Beta MLOps Developer Studio. Become a Beta user by going to our website!
Incorporating bias mitigation methods and fairness metrics into the traditional end-to-end MLOps is called fairness-based machine learning (ML) or fair machine learning. However, fair ML comes with its own challenges. We assembled a diverse team of statisticians and ML experts to provide evidence-based guidance on fairness metrics use/selection and validated code to properly run bias mitigation methods.
EqualityML
WorkflowWe have conducted extensive literature review and theoretical analysis on dozens of fairness metrics and mitigation methods. Theoretical properties of those fairness mitigation methods were analyzed to determine their suitability under various conditions to create our framework for a pre-processing workflow.
Pre-processing Workflow | Tool or Guidance provided |
---|---|
1. Select Fairness Metric | Use our Fairness Metric Selection Questionnaire & Tree to determine appropriate fairness metric(s) |
2. Data Preparation | |
3. Fit Prediction Model | |
4. Compute Model Results and Evaluate Fairness Metric | Use EqualityML method fairness_metric to evaluate the fairness of a model |
5. Run Bias Mitigation | Use EqualityML method bias_mitigation to run various bias mitigation methods on your dataset |
6. Compute Model Results and Fairness Metric After Mitigation | fairness_metric bias_mitigation |
7. Compare Model Results and Fairness Metric Before and After Mitigation | fairness_metric bias_mitigation |
Table 2: The Equality AI recommended pre-processing workflow with tools and guidance made available per step.
We recommend assessing the fairness of the same ML model after bias mitigation is applied. By comparing the predictions before and after mitigation, we will be able to assess whether and to what extent the fairness can be improved. Furthermore, the trade-offs between the accuracy and fairness of the machine learning model will be examined.
In-processing and Post-processing are still under development. Do you need this now? Let us know!
To make fairness metric selection easy we have provided a few essential questions you must answer to identify the appropriate fairness metric for your use case. Click here for the questionnaire. Complete the answers to this questionnaire, then refer to the scoring guide to map your inputs to the desired metrics.
Figure 3: Tree representation of questionnaire.
After identifying the important fairness criteria, we recommend you attempt to use multiple bias mitigation strategies to try to optimize the efficiency-fairness tradeoff.
EqualityML
InstallationThe EqualityML
python package can be installed from PyPI.
pip install equalityml
Clone the last version of this repository:
https://github.com/EqualityAI/EqualityML.git
In the root directory of the project run the command:
poetry install
To run the bunch of tests over the EqualityML package, dependencies shall be first installed before calling pytest.
poetry install --with test
pytest tests
Check out the example below to see how EqualityML can be used to assess fairness metrics and mitigate unwanted bias in the dataset.
from sklearn.linear_model import LogisticRegression
from equalityml import FAIR
import numpy as np
import pandas as pd
# Sample unfair dataset
random_col = np.random.normal(size=30)
sex_col = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
weight_col = [80, 75, 70, 65, 60, 85, 70, 75, 70, 70, 70, 80, 70, 70, 70, 80, 75, 70, 65, 70,
70, 75, 80, 75, 75, 70, 65, 70, 75, 65]
target_col = [1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1,
0, 1, 0, 1, 1, 0, 0, 1, 1, 0]
training_data = pd.DataFrame({"random": random_col, "sex": sex_col, "weight": weight_col,
"Y": target_col})
# Train a machine learning model (for example LogisticRegression)
ml_model = LogisticRegression()
ml_model.fit(training_data.drop(columns="Y"), training_data["Y"])
# Instantiate a FAIR object
fair_obj = FAIR(ml_model=ml_model,
training_data=training_data,
target_variable="Y",
protected_variable="sex",
privileged_class=1)
# Evaluate a fairness metric (for example statistical parity ratio)
metric_name = 'statistical_parity_ratio'
fairness_metric = fair_obj.fairness_metric(metric_name)
# In case the model is unfair in terms of checked fairness metric (value is not close to 1),
# EqualityML provides a range of methods to try to mitigate bias in Machine Learning models.
# For example, we can use 'resampling' to perform mitigation on training dataset.
mitigation_method = "resampling"
mitigation_result = fair_obj.bias_mitigation(mitigation_method)
# Now we can re-train the machine learning model based on that mitigated data and
# evaluate again the fairness metric
mitigated_data = mitigation_result['training_data']
ml_model.fit(mitigated_data.drop(columns="Y"), mitigated_data["Y"])
fair_obj.update_classifier(ml_model)
new_fairness_metric = fair_obj.fairness_metric(metric_name)
# print the unmitigated fairness metric
print(f"Unmitigated fairness metric = {fairness_metric}")
# print the mitigated fairness metric
print(f"Mitigated fairness metric = {new_fairness_metric}")
# All available fairness metrics and bias mitigation can be printed calling the methods:
fair_obj.print_fairness_metrics()
fair_obj.print_bias_mitigation_methods()
The EqualityML
R package can be installed from CRAN:
install.packages("equalityml")
or developer version from GitHub:
devtools::install_github("EqualityAI/equalityml/equalityml-r")
For more details regarding the R package, please check here.
The connections and trade-offs between fairness, explainability, and privacy require a holistic approach to Responsible AI development in the machine learning community. We are starting with the principle of fairness and working towards a solution that incorporates multiple aspects of Responsible AI for data scientists and healthcare professionals. We have much more in the works, and we want to know—what do you need? Do you have a Responsible AI challenge you need to solve? Drop us a line and let’s see how we can help!
Equality AI uses both GitHub and Slack to manage our open source community. To participate:
EqualityML