Fairness Metrics: Demographic Parity, Equalized Odds, and Trade-offs › Individual Fairness

Michael BrenndoerferMarch 16, 20265 min read
Language AI HandbookAll chapters
Part 58 of 67Bias and Fairness
Chapter 444Fairness Metrics: Demographic Parity, Equalized Odds, and Trade-offs › Individual Fairness
Reading section 5 of 13 · Individual Fairness · 5 minSection 5 of 13 · 5 min

Book contents

Section 5 of 13 · 5 min read

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?

Individual Fairness

A classifier ff satisfies individual fairness with respect to a task-specific similarity metric dd if, for all pairs of individuals (xi,xj)(x_i, x_j):

doutput(f(xi),f(xj))≤L⋅dinput(xi,xj)d_{\text{output}}(f(x_i), f(x_j)) \leq L \cdot d_{\text{input}}(x_i, x_j)

where LL is a Lipschitz constant and dinputd_{\text{input}} 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 xix_i and xjx_j are very close in the similarity metric (small dinputd_{\text{input}}), then their predictions must also be close (small doutputd_{\text{output}}). The constant LL controls the maximum allowable sensitivity.

The practical challenge with individual fairness is defining the similarity metric dinputd_{\text{input}}. 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.

In[15]:
Code
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
)
Out[16]:
Visualization
Histogram of prediction differences between cross-group nearest-neighbor pairs, showing a right-skewed distribution.
Distribution of cross-group prediction differences for nearest-neighbor pairs. For each individual in Group 0, we find the 5 most similar individuals in Group 1 (by Euclidean distance in standardized feature space) and compute the average absolute difference in predicted probability. Smaller values indicate better individual fairness. The distribution median and the fraction of pairs with differences above 0.1 are annotated, giving a practical measure of how consistently similar cross-group individuals are treated.
Out[17]:
Console
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.