Fairness Metrics: Demographic Parity, Equalized Odds, and Trade-offs › Individual Fairness
Language AI HandbookAll chapters Fairness Metrics: Demographic Parity, Equalized Odds, and Trade-offs › Individual FairnessOne section · Sections in this chapter5 / 13 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
All the group fairness criteria discussed so far share a common structure: they compare aggregate statistics across two or more demographic groups. This is useful and legally motivated, but it has an important limitation. A model can satisfy demographic parity by making random positive decisions at equal rates, even if it treats very similar individuals from the same group wildly differently. Conversely, a model that always assigns the same score to everyone in a group satisfies group fairness while being completely ignorant of individual circumstances.
Individual fairness asks a different question: are similar individuals treated similarly, regardless of their group membership?
A classifier satisfies individual fairness with respect to a task-specific similarity metric if, for all pairs of individuals :
where is a Lipschitz constant and measures how similar two individuals are in the input space according to the task-relevant similarity metric.
The formal definition, due to Dwork et al. (2012), says the model should be Lipschitz continuous with respect to a meaningful input similarity. Two applicants who are nearly identical in their qualifications should receive nearly identical predictions, regardless of which demographic group they belong to. The Lipschitz condition bounds how much the output can change as a function of how similar two individuals are: if and are very close in the similarity metric (small ), then their predictions must also be close (small ). The constant controls the maximum allowable sensitivity.
The practical challenge with individual fairness is defining the similarity metric . For the definition to be meaningful, the similarity must capture task-relevant similarity, not just numerical distance in feature space. Two candidates with the same GPA from universities of very different selectivity are not equally qualified, but a naive Euclidean distance would treat them as similar. Constructing the right similarity metric often requires domain expertise and can encode its own contested value judgments. What counts as "equally qualified" in hiring? What makes two medical patients "similar" for the purpose of treatment decisions? These are policy questions that cannot be answered by the mathematics alone.
There is also a practical approximation challenge. Verifying individual fairness exactly requires checking every pair of individuals in the dataset, which scales quadratically. In practice, auditors often sample pairs and test consistency, or use Lipschitz-based certificates for specific model classes.
Individual fairness and group fairness are not equivalent and neither implies the other:
- A model can satisfy individual fairness but violate demographic parity, if the demographic groups differ in the feature distribution. If group 0 applicants have systematically higher qualifications, a fair-to-individuals model will approve more of them, creating a demographic parity violation.
- A model can satisfy demographic parity while violating individual fairness, if it randomly selects individuals to reach the target proportions without regard to individual qualifications.
Let's implement a simple individual fairness check based on consistency scores. The idea is to identify pairs of individuals who are similar in the input space but belong to different groups, and measure how different their predictions are.
from sklearn.metrics.pairwise import euclidean_distances
from sklearn.preprocessing import StandardScaler
def compute_individual_fairness_consistency(
X, y_prob, group, n_sample=300, k_neighbors=5, seed=42
):
"""
Estimate individual fairness by finding cross-group nearest neighbors.
For each individual in a random sample, finds the k most similar
individuals from the opposite group (by Euclidean distance in
standardized feature space) and measures the average prediction
difference. Smaller differences indicate better individual fairness.
"""
rng = np.random.default_rng(seed)
scaler = StandardScaler()
X_scaled = scaler.fit_transform(X)
# Sample from each group
idx0 = np.where(group == 0)[0]
idx1 = np.where(group == 1)[0]
sample_size = min(n_sample, len(idx0), len(idx1))
sampled0 = rng.choice(idx0, size=sample_size, replace=False)
sampled1 = rng.choice(idx1, size=sample_size, replace=False)
# Compute pairwise distances between sampled group 0 and group 1
dists = euclidean_distances(X_scaled[sampled0], X_scaled[sampled1])
# For each group-0 individual, find k nearest neighbors in group 1
pred_diffs = []
for i, idx in enumerate(sampled0):
nn_indices = np.argsort(dists[i])[:k_neighbors]
nn_global = sampled1[nn_indices]
pred_diff = np.abs(y_prob[idx] - y_prob[nn_global]).mean()
pred_diffs.append(pred_diff)
return np.array(pred_diffs)
consistency_diffs = compute_individual_fairness_consistency(
X_test, y_prob, group_test, n_sample=300, k_neighbors=5
)
Individual fairness consistency stats: Median cross-group prediction difference: 0.022 Mean cross-group prediction difference: 0.027 90th percentile difference: 0.046 Fraction of pairs with diff > 0.10: 0.007
The individual fairness check quantifies a dimension of unfairness that group metrics miss. Two individuals who are similar in the feature space but belong to different groups may receive substantially different predictions. When the median cross-group difference is large, it means the model has learned a systematic offset that depends on group membership rather than individual characteristics. In our synthetic example, this offset is partly attributable to the data (the biased reported skill scores do differ between groups) and partly a trained artifact of the model learning group-specific patterns.