Digital Developer Conference on Data and AI: Essential data science, machine learning, and AI skills and certification Register for free

IBM Developer Blog

Follow the latest happenings with IBM Developer and stay in the know.

The AI Fairness 360 R package can help R users detect and mitigate bias


AI fairness is an important topic as machine learning models are increasingly used for high-stakes decisions. Machine learning discovers and generalizes patterns in the data and therefore, could replicate systematic advantages of privileged groups. To ensure fairness, we must analyze and address any cognitive bias that might be present in our training data or models.

We are pleased to announce the release of the AI Fairness 360 R package, an open source library containing techniques to help detect and mitigate bias in data sets and machine learning models throughout the AI application lifecycle.

AI application lifecycle

Mitigating bias throughout the AI application lifecycle

The AI Fairness 360 R package includes:

  • A comprehensive set of metrics for data sets and models to test for biases
  • Algorithms to mitigate bias in data sets and models

AI Fairness capabilities

  • Metrics: The AI Fairness 360 R package enables R users to test for bias in their training data with a range of different metrics.

  • Pre-processing algorithms: The pre-processing algorithms within the toolset allow users to modify the training data to reduce or remove this bias. The data can now be used to build a fairer model.

  • In-processing algorithms: The in-processing algorithms within the toolset build machine learning models accounting for fairness. Rather than modifying the data, the algorithms consider the protected attributes to build a fairer machine learning model.

  • Post-processing: The post-processing algorithms allow the user to modify predictions made from an existing machine learning model for fairness. These are designed for an R user who is unable to modify the original data or already has a working model.

To determine which metrics and algorithms are most appropriate for a given use case, take a look at this guidance material.

Getting started

You can install the development version of aif360 from GitHub with the following command.

# install.packages("devtools")
devtools::install_github("IBM/AIF360/aif360/aif360-r")

Then, use the install_aif360() function to install AIF 360.

library(aif360)
install_aif360()
load_aif360_lib()

This package is currently under CRAN review.

Examples

# Load census income dataset [https://archive.ics.uci.edu/ml/datasets/adult](https://archive.ics.uci.edu/ml/datasets/adult)
ad <- adult_dataset()

# Specify the protected class and privileged & unprivileged classes
privileged <- list("race", 1)
unprivileged <- list("race", 0)

# Creating a dataset metric to evaluate fairness
dm <- binary_label_dataset_metric(ad, privileged, unprivileged)

# Calculate the disparate impact value
dm$disparate_impact()

Contributing

We have developed the package with extensibility in mind. This library is still in development, so we encourage the contribution of your metrics, explainers, and debiasing algorithms.

If you’d like to contribute to the development of aif360, read these guidelines.

Note that the aif360 project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.