Fairness Metrics in Machine Learning
Fairness isn't one number
Once dataset bias is detected, the next challenge is defining what 'fair' means precisely enough to measure and optimize for. This turns out to be genuinely hard: there are multiple, mathematically incompatible definitions of fairness in common use, each formalizing a different intuition about what equal treatment should mean, and a classifier can satisfy one definition while clearly violating another on the exact same data. Choosing a fairness metric is a value judgment about the problem, not a purely technical decision — the math only tells you the consequences of the choice.
Group fairness definitions
Demographic parity (statistical parity) requires the positive prediction rate to be equal across groups: $P(\hat{Y}=1 \mid A=a) = P(\hat{Y}=1 \mid A=b)$, ignoring the true outcome entirely. Equalized odds requires both the true positive rate and false positive rate to be equal across groups: $P(\hat{Y}=1 \mid Y=y, A=a) = P(\hat{Y}=1 \mid Y=y, A=b)$ for each outcome $y$ — a stricter, outcome-aware notion. Equal opportunity is a relaxation of equalized odds requiring only the true positive rate to match across groups (equal chance of being correctly identified when the true label is positive), relevant in settings like loan approval where false negatives (denying a qualified applicant) carry most of the ethical weight.
import numpy as np
def group_metrics(y_true, y_pred, group):
"""Compute TPR, FPR, and positive rate for one group's slice."""
mask = y_true == 1
tpr = np.mean(y_pred[mask] == 1) if mask.sum() > 0 else float("nan")
fpr = np.mean(y_pred[~mask] == 1) if (~mask).sum() > 0 else float("nan")
positive_rate = np.mean(y_pred == 1)
return {"group": group, "tpr": tpr, "fpr": fpr, "positive_rate": positive_rate}
def demographic_parity_gap(metrics_a, metrics_b):
return abs(metrics_a["positive_rate"] - metrics_b["positive_rate"])
def equalized_odds_gap(metrics_a, metrics_b):
return max(abs(metrics_a["tpr"] - metrics_b["tpr"]), abs(metrics_a["fpr"] - metrics_b["fpr"]))Common fairness metrics compared
| Metric | Requires equal across groups | Ignores true labels? |
|---|---|---|
| Demographic parity | Positive prediction rate | Yes — pure outcome-blind parity |
| Equalized odds | TPR and FPR | No — conditions on true label |
| Equal opportunity | TPR only | No — conditions on positive true label |
| Predictive parity | Precision (PPV) | No — conditions on predicted label |
| Calibration within groups | Predicted probability matches true frequency per group | No |
The impossibility result
Individual fairness and causal approaches
Group fairness metrics all operate at the population level and can be satisfied while still treating specific similar individuals very differently. Individual fairness instead requires that similar individuals receive similar predictions, formalized as a Lipschitz-continuity condition relative to some task-specific similarity metric — the catch is that defining 'similar' in a way that doesn't itself encode bias is its own hard, contestable problem. Causal fairness approaches go further, asking whether a protected attribute causally affects the outcome through an illegitimate pathway (e.g. via a proxy variable) versus a legitimate one, requiring a causal model of the domain rather than purely statistical analysis of observed correlations.
Choosing a metric for a real system
In practice, selecting a fairness metric requires engaging with the actual decision being made: what are the relative costs of false positives versus false negatives for each group, and which type of error does the deployment context make most consequential? A hiring system and a medical screening system might reasonably prioritize different fairness definitions even with structurally similar classifiers, because the harms of a false negative versus false positive differ. This is why fairness work increasingly treats metric selection as a stakeholder and domain-expert conversation, with the technical implementation following from that discussion rather than preceding it.
What's Next?
Fairness metrics measure how a model's outputs treat different groups; a related but distinct concern is what the training process itself reveals or leaks about the individuals whose data it was trained on, which is where privacy-preserving machine learning techniques come in.
I build these systems professionally.
Whether it's a RAG pipeline, analytics migration, or AI workflow — let's talk.