Explainer: What is a Proxy Variable?

September 19, 2026 · View on GitHub

The sneaky reason AI stays biased even after you remove race from the data.


The One-Sentence Definition

A proxy variable is a data feature that correlates with a protected attribute (like race, gender, or class) even though it doesn't mention it directly - so removing the protected attribute from a model doesn't remove the bias it encodes.


Why This Matters

Most people assume that removing race from an AI model makes it race-neutral. This is wrong.

Machine learning models don't care what a feature is called. They care what it predicts. If a feature like custody_status or zip_code is correlated with race in the training data, the model will learn and use that correlation - whether or not the word "race" appears anywhere in the dataset.

This is called proxy discrimination, and it's one of the hardest problems in algorithmic fairness.


Common Proxy Variables

FeatureProtected Attribute It EncodesWhy
Zip codeRaceHistorical redlining segregated neighborhoods by race. Zip codes still reflect this.
Custody statusRaceOver-policing of Black communities leads to disproportionate pretrial detention.
NameGender / EthnicityNames encode gender and ethnicity with high accuracy.
College attendedSocioeconomic backgroundElite colleges remain heavily stratified by class and race.
Credit scoreRace / ClassCredit histories reflect historical exclusion from banking.
Prior arrestsRaceArrest records reflect over-policing, not actual crime rates.

Real-World Proof: COMPAS Analysis

We tested this directly using the ProPublica COMPAS dataset.

What We Did

Step 1 - Biased model (includes race + proxies):

# compas-scores-raw.csv has no raw `race`/`sex` columns - race_binary is
# derived from Ethnic_Code_Text, exactly as unfair.py does
df['race_binary'] = df['Ethnic_Code_Text'].map({'African-American': 1, 'Caucasian': 0})
X = pd.get_dummies(df[[
    'race_binary',
    'Sex_Code_Text',
    'CustodyStatus',        # proxy for race
    'MaritalStatus'
]])

Results:

GroupHigh-Risk Flag Rate
Black defendants87.16%
White defendants0.40%
Fairness gap86.77%

Step 2 - Remove race only (naive approach):

Many developers stop here. They drop race_binary and assume the model is now fair. Dropping race alone already takes the gap from 86.77% down to 18.38% - most of the signal was riding on race directly. But it isn't fully fixed: CustodyStatus is still acting as a racial proxy, and its own marginal contribution beyond race is the remaining ~2.7 points down to 15.69% once it's removed too (see Step 3).


Step 3 - Remove race AND known proxies (our fix):

X = pd.get_dummies(df[[
    'Sex_Code_Text',
    'MaritalStatus'
    # Race removed ✓
    # CustodyStatus removed ✓ (proxy for race)
]])

Results:

GroupHigh-Risk Flag Rate
Black defendants84.71%
White defendants69.02%
Fairness gap15.69%

Summary

ApproachFairness GapReduction
Biased model86.77%-
Remove race only18.38%79%
Remove race + proxy15.69%82%

Removing the protected attribute alone is not enough. You must audit every feature for correlation with protected attributes.


How to Detect Proxy Variables

import pandas as pd
from scipy.stats import chi2_contingency

def check_proxy(df, feature, protected_attr):
    """
    Check if a feature is a proxy for a protected attribute
    using a chi-squared test of independence.
    Returns p-value - if < 0.05, likely a proxy.
    """
    contingency = pd.crosstab(df[feature], df[protected_attr])
    chi2, p, dof, expected = chi2_contingency(contingency)
    return {
        'feature': feature,
        'protected_attr': protected_attr,
        'p_value': round(p, 4),
        'is_proxy': p < 0.05
    }

# Example usage
result = check_proxy(df, 'CustodyStatus', 'Ethnic_Code_Text')
print(result)
# {'feature': 'CustodyStatus', 'protected_attr': 'Ethnic_Code_Text', 'p_value': 0.0, 'is_proxy': True}

Run this on every feature in your dataset before training. Any feature with is_proxy: True needs careful consideration - either remove it or apply fairness-aware techniques.


The Bigger Picture

Proxy variables exist because our social world is stratified. Zip codes encode race because of redlining. Custody records encode race because of over-policing. Credit scores encode class because of historical exclusion.

Data doesn't exist in a vacuum. It reflects the society that generated it. A model trained on that data will learn those reflections - unless you actively audit and intervene.

This is why algorithmic auditing is not optional. It is a prerequisite for deployment.


  • COMPAS/ - Full COMPAS analysis: biased model → fair model → 82% gap reduction
  • AI Fair Recruitment/ - AI recruitment bias: 97.3% gap reduction after feature audit
  • Coming soon: Facial recognition bias, HMDA loan bias, healthcare AI

Further Reading


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