Fairness in Machine Learning: Pre-Processing Algorithms

Carolyn Saplicki
IBM Data Science in Practice
5 min readMar 13, 2023

--

Co-authored by Carolyn Saplicki, Senior Data Scientist with Expert Labs, and Mitali Bante, Data Scientist with Expert Labs.

In our previous blog, Fairness Explained: Definitions and Metrics, we discuss fairness definitions and fairness metrics through a real-world example. This sets the stage for how bias can be identified in machine learning. Specifically, we utilize tools such as the Fairness Compass and AI Fairness 360 to understand the existence of bias and quantify its effects. The next crucial step is to take measures to mitigate bias. This blog focuses on pre-processing algorithms.

Bias Mitigation

There are several approaches to bias mitigation, which can be categorized into three categories: pre-processing, in-processing, and post-processing.

Pre-processing algorithms involve modifying the dataset before training the model to remove or reduce the bias present in the data. Pre-processing algorithms are useful when the bias in the data is known or can be easily identified.

In-processing algorithms aim to reduce bias during the model training process. In-processing algorithms are useful when the bias in the data is not easily identifiable or when the dataset is too large to pre-process.

Post-processing algorithms involve modifying the output of the model after it has been trained. Post-processing algorithms are useful when the model is already trained, and the bias in the predictions is identified after deployment.

Pre-Processing Algorithms

Pre-processing algorithms are bias mitigation algorithms applied to training data, attempting to improve fairness metrics. These algorithms are the earliest mediation category and give the most flexibility to correct bias.

Pre-processing algorithms can only be utilized if a user is allowed to modify the training data before model building. This means pre-processing algorithms should not include fairness metrics that involve model predictions such as predictive parity.

AIF360 Methods

Below are the pre-processing algorithms found in AI Fairness 360 and some key take-aways.

Disparate-Impact Remover

Disparate-Impact Remover (DIR) increases group fairness by ensuring balanced representation of different protected groups. The DIR algorithm works by adjusting the features in the dataset so the distribution of these features is equal across all protected groups. Learn more about how Disparate-Impact Remover works and check out an AIF360 code demo.

  • Primarily addresses group fairness (geared towards improving disparate impact)
  • Creates modified datasets in the same space as training data
  • Useful if pre-processing requires transparency

Learning Fair Representations

Learning Fair Representations (LFR) finds a latent representation that encodes the data well but obfuscates information about protected attributes. The LFR algorithm works by identifying sensitive attributes and creating a new set of features by encoding the sensitive attributes, removing any association between the attributes and the output variable. Learn more about how Learning Fair Representations works and check out an AIF360 code demo.

  • Addresses group and individual fairness
  • Creates modified datasets in a latent space (mapping each individual to a probability distribution you can make classifications on)

Optimized Pre-Processing

Optimized Pre-Processing edits features and labels in the data with group fairness, individual distortion and data fidelity constraints and objectives through a probabilistic transformation. Learn more about how Optimized Pre-Processing works and check out an AIF360 code demo.

  • Primarily addresses group fairness while accounting for individual fairness
  • Creates modified datasets in the same space as training data
  • Useful if pre-processing requires transparency

Reweighing

Reweighing generates weights for the training samples in each (group, label) combination differently, ensuring fairness before classification. Reweighing only changes weights applied to training samples (not any feature/label values). The reweighing algorithm first identifies sensitive attributes in the dataset and computes the weights for each instance. Higher weights are assigned to instances that are underrepresented and lower weights are assigned to instances that are overrepresented. Learn more about how Reweighing works and check out an AIF360 code demo.

  • Addresses group fairness (geared towards improving statistical parity)
  • Creates modified datasets in the same space as training data
  • Useful if unable to apply value changes

Best Practices

  1. Remove bias as early as possible during the ML lifecycle!
  2. All pre-processing algorithms should be tried on the training data. The algorithm(s) that remove the most bias should be utilized. Disparate-Impact Remover and Optimized Pre-Processing are useful if pre-processing requires transparency on the transformation.
  3. If algorithms are being compared to each other, ensure they are compared based on the same dataset and preprocessing. For algorithms that only work with numerical features, try one-hot encoding or target encoding for categorical features.
  4. Furthermore, a single train/test split is insufficient. We recommend utilizing multiple randomized train/test splits or a K-fold validation. This will test stability of the algorithm.
  5. Compare algorithms outcomes based on multiple metrics (accuracy, fairness, ROC, etc).
  6. There is a trade-off between fairness and accuracy. When applicable, use hyperparameter tuning to explore the possible solution space.

FAQs

When to conclude a pre-processing bias mitigation algorithm is needed?

Existence of bias in your data can be determined by using the fairness metrics in AIF360.

When to use which algorithm?

Currently, AI Fairness 360 suggests all pre-processing algorithms, “should be tested because the ultimate performance depends on dataset characteristics: there is no one best algorithm independent of dataset.” If you need transparency about the pre-processing transformation, Disparate-Impact remover and Optimized Pre-Processing are ideal.

What if I have multiple protected attributes?

Utilize multiple algorithms to investigate and mitigate bias for each protected attribute. Ensure you follow the same process each time you employ pre-processing algorithms. Optimized Pre-Processing and Reweighing can mitigate bias for multiple protected attributes at once.

What about other bias-mitigation methods?

Other bias mitigation methods can be utilized with pre-processing algorithms. Again, it is best practice to remove bias as early as possible during the ML lifecycle.

How much bias removal matters?

Any bias removal matters in machine learning. If a pre-processing algorithm can reduce the status quo of bias, it should be utilized. Often, multiple algorithms are used to reduce the presence of bias in a machine learning model.

What if data is not accessible to perform pre-processing bias mitigation?

As mentioned, it’s better to perform bias mitigation at the earliest stage in machine learning model development cycle, but if it cannot be performed during pre-processing, you can try in-processing or post-processing bias mitigation algorithms.

#IBM #MachineLearning #Fairness #PreProcessing #BiasMitigation

--

--