← Back to explainers
Explainer

Choosing a Fairness Metric

Start from the harm, not from the formula.

Learn a decision path from the harm you worry about to the metric that measures it. See the benchmark's own results: in 9 of 13 audit and attribute pairs some fairness metrics are significant and others are not, so the choice changes the verdict.

There is no best fairness metric. There is the metric that measures the harm you are trying to prevent, and the others that will disagree with it.

The One-Sentence Definition

Choosing a fairness metric is deciding which group-level comparison matches the harm at stake and the standard you are held to, before looking at any numbers.

Why It Matters

The metrics in this repo answer different questions: Demographic Parity asks whether groups are selected at the same rate, Equal Opportunity whether qualified people are accepted at the same rate, Predictive Parity whether a positive means the same thing for everyone. They are not interchangeable and, outside special cases, they cannot all hold at once (Fairness Metric Conflicts).

That makes the choice consequential. Pick afterwards and you can find a metric that says what you hoped. The benchmark's own results show how often they diverge.

Core Concept: Start From the Harm

Work backwards from what goes wrong for a person:

The harmWho it hitsThe questionStart with
Not selected when you should have beenQualified people in one groupAre qualified people accepted at the same rate?Equal Opportunity
Wrongly flagged or deniedPeople who would have been fineAre false flags equally common?False positive rate, in Equalized Odds
Unequal access to a benefitEveryone in a groupAre groups selected at the same rate?Demographic Parity and Disparate Impact
A score that means different thingsPeople relying on the scoreDoes a positive predict the outcome equally?Predictive Parity and Calibration
One group is simply worse servedThe worst-off groupHow well off is the worst group?Max-Min (Rawlsian) Fairness

Then check the standard you are held to (a legal threshold such as the 80% rule, a regulator's named metric), and what the label means: if the label is itself biased (Label Bias), the error-rate metrics inherit it and demographic parity may be the safer reading.

Concrete Example: The Benchmark's Own Results

For every audit and protected attribute, take the benchmark's S2 model (logistic regression, no protected column, no proxies) in results/ (the current results) and list which of the six metrics are significant. If the metrics agreed, each row would be all or nothing.

audit                    attribute        flagged  which metrics are significant
ai_fair_recruitment      gender           1/6     accuracy_equality
benefits_denial          age              3/6     accuracy_equality, demographic_parity, disparate_impact_ratio
benefits_denial          national_origin  1/6     accuracy_equality
benefits_denial          race             3/6     accuracy_equality, demographic_parity, disparate_impact_ratio
benefits_denial          sex              4/6     accuracy_equality, demographic_parity, disparate_impact_ratio, predictive_parity
compas                   race             6/6     accuracy_equality, demographic_parity, disparate_impact_ratio, equal_opportunity, equalized_odds, predictive_parity
german_credit_lending    age              0/6     -
healthcare_readmission   age              3/6     accuracy_equality, demographic_parity, disparate_impact_ratio
healthcare_readmission   gender           3/6     accuracy_equality, demographic_parity, disparate_impact_ratio
healthcare_readmission   race             1/6     accuracy_equality
insurance_denial         age              0/6     -
insurance_denial         gender           0/6     -
tenant_screening         race             4/6     demographic_parity, disparate_impact_ratio, equal_opportunity, equalized_odds

9 of 13 audit/attribute pairs have some metrics significant and others not.

They mostly do not agree. COMPAS fails all six. German Credit and Insurance Denial fail none. The other 9 of 13 pairs fail some and pass others: Benefits Denial by sex fails demographic parity, disparate impact, accuracy equality and predictive parity but not equal opportunity or equalized odds, while Tenant Screening by race is the reverse for predictive parity and accuracy equality. The same model, the same audit, and the verdict depends on the metric.

Three worked paths from the repo's audits:

Detection/Implementation Code

Run from the repo root (PYTHONPATH=. python3 explainers/code/choosing-a-fairness-metric.py; that file is generated from the block below). It reads the benchmark's current results; change strategy or model to look at another.

import pandas as pd

results = pd.read_csv("results/results_fairness.csv")      # the benchmark's current results
base = results[(results.strategy == "unawareness_proxy_removal") & (results.model == "logistic_regression")
               & ~results.protected_attribute.str.contains("_x_")]
rows = []
for (audit, attribute), group in base.groupby(["audit", "protected_attribute"]):
    flagged = sorted(group[group.significant == True].metric)    # noqa: E712 - a boolean column
    rows.append((audit, attribute, len(flagged), len(group), ", ".join(m.replace("_diff", "") for m in flagged)))

print(f"{'audit':24s} {'attribute':16s} flagged  which metrics are significant")
for audit, attribute, n_flagged, n_total, which in rows:
    print(f"{audit:24s} {attribute:16s} {n_flagged}/{n_total}     {which or '-'}")

split = [r for r in rows if 0 < r[2] < r[3]]
print(f"\n{len(split)} of {len(rows)} audit/attribute pairs have some metrics significant and others not.")

Limitations

  1. "Significant" depends on sample size. A metric can look fine because the group is small, see Permutation Tests for Fairness Gaps.
  2. The table assumes the label is right. If the label is biased, every error-rate row inherits it.
  3. One metric is rarely enough. Reporting the chosen metric plus the ones that disagree is more honest than reporting one.
  4. Legal standards decide some choices. Where a regulator names a metric, the choice is made for you.
  5. The conflicts are mathematical. When base rates differ, no model can satisfy calibration and equal error rates together, see Fairness Metric Conflicts.

Further Reading


Part of The Fair Code Project - exposing and fixing algorithmic bias with real data and open code.