Abstract
The increasing use of Machine Learning (ML) software can lead to unfair and unethical decisions, thus fairness bugs in software are becoming a growing concern. Addressing these fairness bugs often involves sacrificing ML performance, such as accuracy. To address this issue, we present a novel counterfactual approach that uses counterfactual thinking to tackle the root causes of bias in ML software. In addition, our approach combines models optimized for both performance and fairness, resulting in an optimal solution in both aspects. We conducted a thorough evaluation of our approach on 10 benchmark tasks using a combination of 5 performance metrics, 3 fairness metrics, and 15 measurement scenarios, all applied to 8 real-world datasets. The conducted extensive evaluations show that the proposed method significantly improves the fairness of ML software while maintaining competitive performance, outperforming state-of-the-art solutions in 84.6% of overall cases based on a recent benchmarking tool.
Introduction
Machine Learning (ML) models are increasingly deployed for high-stakes decision-making in domains such as credit scoring, hiring, and criminal recidivism prediction. However, these models frequently inherit and amplify human biases present in historical training data. Existing debiasing techniques often struggle with two primary challenges: the "Fairness-Accuracy Trade-off," where improving fairness leads to significant performance drops, and "Coarse-grained Sampling," where methods like random undersampling inefficiently treat all data points as equally biased.
The CFSA Framework
To address these limitations, we developed the Counterfactual Fair Software Approach (CFSA). Unlike traditional methods that rely on random sampling, CFSA identifies and addresses specific biased examples within the training data using "counterfactual thinking."
The framework operates through a multi-stage pipeline:
- Counterfactual Bias Test (CBTest): For every individual in the training set, the system creates a "counterfactual" version by altering only the sensitive attribute (e.g., changing gender). It then measures the Flip Test (change in predicted label) and the Deviation Test (shift in prediction probability).
- CBList Ranking: Training examples are ranked based on their CBTest scores to identify the "root causes" of bias—specific data points where sensitive attributes most strongly influence outcomes.
- Targeted Debiasing: CFSA removes the highest-ranked biased examples and uses Fair Synthesis to generate new, unbiased examples, maintaining class balance while satisfying the "We Are All Equal" (WAE) worldview.
- Ensemble Training: The framework trains two models: a Performance Model on original data and a Fairness Model on debiased data. By ensembling their outputs (typically with a 0.6-0.4 weight split), developers can achieve an optimal balance between accuracy and fairness.
Experimental Setup
We evaluated CFSA on eight real-world datasets covering various domains, including financial (Adult, Bank, German, Default), criminological (COMPAS), social/medical (Dutch, Heart), and educational (Law). These datasets are well-known in the fairness community for containing significant gender, race, or age biases.
Key Insights
A core finding of this work is that bias is not distributed equally across a dataset. By ranking data points via the CBList, we demonstrate that removing the "most biased" individuals is far more effective than random thinning. Furthermore, using counterfactuals as a diagnostic tool allows the framework to "interrogate" the data, identifying points where decisions rely too heavily on sensitive attributes. Finally, the ensemble approach acknowledges that fairness and accuracy are often competing goals, providing a smoother Pareto frontier for developers.
Key Results
CFSA demonstrates significant improvements over existing methods. In 85% of cases evaluated using the Fairea benchmarking tool, CFSA achieved a "win-win" trade-off, where fairness improved significantly with minimal or no accuracy loss.
Extensive evaluations show that CFSA outperformed state-of-the-art solutions like MAAT and Fair-SMOTE in 84.6% of overall cases across 15 measurement scenarios. The method proved model-agnostic, showing effectiveness with Logistic Regression, SVM, and Random Forest models. Additionally, CFSA successfully handles multi-attribute fairness, reducing bias for multiple sensitive attributes simultaneously.
Conclusion and Future Work
CFSA offers a robust framework for building fairer ML software without sacrificing performance. While highly effective on tabular data, future work will explore expanding this approach to more complex data modalities like text and images. We also plan to validate the framework on diverse industrial datasets and investigate automated mechanisms for optimizing ensemble weights.
Summary updated