Easy Ways to Check a Model for Bias
While learning about ethical issues in ML models, I came across some resources for testing and investigating bias. This is relevant in ML, since a model can score well overall and still treat one group worse than another. A test metric like Accuracy would not show that. Instead you’d have to split the results by group and compare, or implement a different systematic approach. Here are two free tools I found from my graduate coursework at Georgia Tech.
What-If Tool
The What-If Tool (WIT) comes from Google’s PAIR team. It’s a visual interface for poking at a trained model with very little code. It runs in Jupyter or Colab notebooks and in TensorBoard, and it works with classification and regression models on tabular, image, or text data.
The useful parts for bias checks:
- Slice by a feature. Split results by something like gender and see a separate confusion matrix and ROC curve for each group.
- Counterfactuals. Pick a data point and jump to the most similar one that got a different prediction. Good for seeing what actually flips the model’s answer.
- Edit and re-run. Change one feature on an example and see how the prediction moves.
- Threshold tuning. For binary classifiers, adjust the decision threshold per group, or set it based on fairness goals like equal opportunity or demographic parity.
In a notebook it’s pip install witwidget. Source and demo notebooks are on GitHub.
AI Fairness 360
AI Fairness 360 (AIF360) is an open-source toolkit, originally from IBM Research, available in Python and R. Where WIT is about looking, AIF360 is about measuring. It has a big set of fairness metrics for both datasets and models, plus algorithms to reduce bias before, during, or after training. Install with pip install aif360.
The paper behind it explains the design if you want the background.
For a trained classifier, the main class is ClassificationMetric. You give it two datasets, one with the true labels and one with the model’s predictions, plus which groups count as privileged and unprivileged. Then you call whichever metrics you want.
A few metrics to start with
All of these compare the unprivileged group to the privileged group.
- Disparate impact: the rate of favorable predictions for the unprivileged group divided by the rate for the privileged group. 1 means equal.
- Statistical parity difference: the same two rates, subtracted instead of divided. 0 means equal.
- Equal opportunity difference: the gap in true positive rates. Of the people who should get the favorable outcome, does each group get it at the same rate?
- Average odds difference: the average of the gaps in false positive rate and true positive rate. 0 means equal odds.
The first two only look at predictions. The last two also use the true labels, so they tell you whether the model’s mistakes land evenly.
Disclaimer - I do not own any of these tools, nor endorse them as best tools to investigate bias for models. Note that no single number settles whether a model is fair, and domain knowledge along with peer-reviewed ethical standards are better than some advice you get from a blogpost. These are checks, not a verdict. That being said, minor checks like these are better than not checking at all.