Skip to content
AI360Xpert
Core ML

Fairness Mitigation

Finding bias is step one. Step two is fixing it by altering the training data, tweaking the learning process itself, or adjusting the predictions after the fact.

The three stages where fairness interventions can be applied to an ML pipeline.
The three stages where fairness interventions can be applied to an ML pipeline.

Why Does This Exist?

Once you have chosen a fairness metric and discovered that your model violates it, you must intervene. Machine learning models do not magically unlearn historical biases on their own; in fact, they tend to amplify them.

Fairness mitigation techniques exist to mathematically constrain or adjust the model so that its outputs satisfy your chosen fairness definition. Because machine learning is a pipeline, you can intervene at three distinct stages: before training (the data), during training (the algorithm), or after training (the predictions).

Think of It Like This

Think of It Like This

Imagine you are a teacher realizing your grading history shows a bias against students who write left-handed, because left-handed ink smudges and you unconsciously dock points for neatness.

Pre-processing (Data): You force all students to type their assignments instead of handwriting them before you even look at them. You've removed the source of the bias from the input.

In-processing (Algorithm): You change your grading rubric explicitly, adding a rule: "Do not deduct points for smudges." You change how you learn to score.

Post-processing (Predictions): You grade normally, but before returning the tests, you look at all left-handed students' grades and artificially bump them up by 5 points to equalize the averages.

How It Actually Works

Mitigation algorithms are grouped by where they sit in the pipeline. Each has trade-offs regarding access requirements and impact on accuracy.

1. Pre-processing (Fix the Data)

These methods transform the training data before it ever touches a model. The goal is to remove the correlation between the protected attribute and the target variable or other features.

  • Reweighing: Assigns different weights to examples in the training data. For example, if historically marginalized individuals with positive outcomes are rare, those specific rows get higher sample weights during training so the model pays more attention to them.
  • Disparate Impact Remover: Edits feature values to ensure the distributions of features are identical across different demographic groups, effectively scrubbing the protected attribute's proxy signal from the dataset.

Trade-off: Pre-processing gives you the most flexibility because any standard ML algorithm can be trained on the cleaned data. However, it cannot prevent the model from discovering new, complex proxy variables during training.

2. In-processing (Fix the Algorithm)

These methods change the objective function of the machine learning algorithm itself. Instead of just minimizing error, the model minimizes error while satisfying a fairness constraint.

  • Adversarial Debiasing: You train two neural networks simultaneously. The predictor tries to predict the target variable. The adversary looks at the predictor's output and tries to guess the protected attribute. The predictor is penalized if the adversary succeeds. The network learns to make predictions that contain zero information about race or gender.
  • Fairness Constraints: For models like logistic regression or SVMs, mathematical constraints are added to the loss function penalizing the difference in false positive rates between groups.

Trade-off: In-processing usually achieves the best balance of fairness and accuracy. However, it requires modifying the training code, which is impossible if you are using a black-box API or a pre-compiled model.

3. Post-processing (Fix the Predictions)

These methods take a trained, biased model and adjust its predictions.

  • Threshold Optimization: You find the optimal decision threshold (e.g., 0.5) for predicting a positive class. Instead of using one threshold for everyone, you use different thresholds for different groups to force Equal Opportunity or Demographic Parity. For example, the threshold for Group A might be 0.45 and Group B 0.55.
  • Reject Option Classification: For predictions that fall in the "uncertain" region (close to the decision boundary), you systematically swap the predictions for the unprivileged group to favorable outcomes.

Trade-off: Post-processing is the easiest to implement because it requires no access to the training data or the model's internals. However, setting different thresholds for different demographic groups is often illegal in domains like hiring or lending (e.g., disparate treatment under US law).

Show Me the Code

This example shows a simple post-processing technique: adjusting thresholds per group to balance True Positive Rates (Equal Opportunity).

import numpy as np
def post_process_thresholds(y_proba, sensitive_attr, priv_group, unpriv_group, priv_thresh, unpriv_thresh):    """Applies different decision thresholds based on group membership."""        y_pred = np.zeros_like(y_proba)        # Apply privileged threshold    priv_mask = (sensitive_attr == priv_group)    y_pred[priv_mask] = (y_proba[priv_mask] >= priv_thresh).astype(int)        # Apply unprivileged threshold    unpriv_mask = (sensitive_attr == unpriv_group)    y_pred[unpriv_mask] = (y_proba[unpriv_mask] >= unpriv_thresh).astype(int)        return y_pred
# Example usage:# y_proba = np.array([0.8, 0.6, 0.4, 0.7, 0.5, 0.3])# sensitive_attr = np.array(['M', 'M', 'M', 'F', 'F', 'F'])# # Lower threshold for females to boost their TPR# preds = post_process_thresholds(y_proba, sensitive_attr, 'M', 'F', 0.6, 0.4)# -> array([1, 1, 0, 1, 1, 0])

Watch Out For

The Fairness-Accuracy Trade-off

In almost all real-world scenarios, forcing a model to satisfy a fairness constraint will lower its overall accuracy. You are forcing the model to deviate from the mathematically optimal fit to historical data. You must be prepared to accept this trade-off.

Legal risks of Post-processing

Explicitly using a protected attribute (like race) at inference time to change a prediction or apply a different threshold is explicitly illegal in many regulated industries. In those domains, you must use Pre-processing or In-processing.

The Quick Version

  • Pre-processing alters the training data (e.g., reweighing samples) to remove bias before training begins.
  • In-processing alters the training algorithm (e.g., adversarial debiasing) to optimize for both accuracy and fairness simultaneously.
  • Post-processing alters the model's outputs (e.g., group-specific thresholds) to force the final predictions to meet a fairness metric.
  • Each method has trade-offs regarding how much access you need to the model pipeline and what is legally permissible in your domain.

Related concepts