Fairness, Interpretability & Causality
Making models fair, understandable and causally sound.
A model can be accurate and still be unfair, inscrutable, and useless for deciding what to do. This lesson takes on the three questions every consequential model eventually faces. Is it fair, and by which definition? Why does it predict what it predicts? Would acting on its prediction change the outcome? Each question has precise tools, and each tool has limits you need to know.
What you’ll learn
- Trace unfairness to its sources (biased labels, proxy targets, unrepresentative data, feedback loops) and explain why removing the protected attribute does not remove it.
- Define demographic parity, equal opportunity, equalized odds and calibration within groups, and derive the identity that makes them conflict when base rates differ.
- Distinguish global from local and intrinsic from post-hoc interpretability, and compute partial dependence and Shapley attributions for simple models.
- Explain why a predictive model cannot answer "what if we intervene?", how confounding misleads, and how randomization and adjustment recover causal effects.
Where unfairness comes from
A model learns the patterns in its data, including the ones nobody wanted. Fairness problems rarely come from a malicious line of code; they enter through what is measured, who is sampled and which outcome is used as the label.
| Source | How it enters | Example |
|---|---|---|
| Historical bias | labels record past decisions, not ground truth | a hiring model trained on whom managers hired learns their preferences, not who would have done the job well |
| Proxy targets | the label is a convenient stand-in for what you care about | a widely used health-care algorithm predicted future costs as a proxy for health needs; because less was spent on Black patients with the same needs, at a given risk score Black patients were considerably sicker than White patients (Obermeyer, Powers, Vogeli & Mullainathan, 2019) |
| Unrepresentative data | some groups are scarce in training data, so errors concentrate there | three commercial gender classifiers erred on up to 34.7% of darker-skinned women but at most 0.8% of lighter-skinned men (Buolamwini & Gebru, 2018) |
| Feedback loops | decisions shape the data the next model learns from | patrols sent where incidents were recorded record more incidents there (lesson Deployment & a Changing World) |
The obvious fix, deleting the protected attribute from the inputs ("fairness through unawareness"), rarely works. Postal codes, names, schools, purchase histories and dozens of weak signals together predict group membership well, so a flexible model reconstructs it whenever it helps fit the labels. Worse, deleting the attribute makes it impossible to measure disparities. The criteria below are stated in terms of the attribute precisely so that they can be checked.
A lender removes race from its model's inputs, but keeps postal code, income and employment history. An audit finds approval rates still differ sharply by race among otherwise similar applicants. What is the most likely reason?
- The audit is wrong: a model that never sees race cannot treat races differently
- The remaining features act as proxies that encode race, and the model uses them
- Removing a feature always increases bias
- The model must have been trained with race and then had it removed incorrectly
Show the answer
B. The remaining features act as proxies that encode race, and the model uses them
Correlated features carry the information the deleted attribute carried. If those features help fit labels shaped by historical disparities, the model will use them, and the disparity survives under another name.
Group fairness, made precise
Write for group membership, for the true outcome (1 = would repay), for the decision and for a risk score. Most group criteria compare a rate across groups; they differ in which rate:
| Criterion | Requires, for all groups | In words |
|---|---|---|
| Demographic parity | equal approval rates | |
| Equal opportunity | equal true-positive rates: people who would repay are approved equally often | |
| Equalized odds | equal true-positive and false-positive rates | errors are equally likely in both groups, among repayers and among defaulters |
| Calibration within groups | for every and | a score of 70% means 70% in every group |
Why you cannot have them all
The conflict in the widget is not an artifact of its data. When the groups' base rates differ, simple arithmetic ties the error rates together. Take one group, with base rate , and a classifier with positive predictive value , false-negative rate and false-positive rate .
In a group of people, are positive and the classifier catches a fraction of them:
The definition of PPV, , fixes the number of false positives:
Divide by the negatives. If two groups share the same PPV and FNR but have different base rates , their false-positive rates must differ:
Both groups get PPV 0.8 and FNR 0.2. Group A's base rate is 0.5, so its FPR is . Group B's base rate is 0.3. What is B's false-positive rate, in percent?
Show the answer
8.6 %
, about 8.6%. Equal predictive value and equal miss rates force the false-positive rates apart, here by more than a factor of two. The widget's data obey the same identity: at the equal-opportunity thresholds A 59 and B 53 the true-positive rates are 72% and 70%, while the predictive values are 92.3% and 56.0% and the false-positive rates 6.0% and 23.6%. With the miss rates matched, predictive value and false-positive rate cannot both match as well.
This arithmetic sat at the heart of a public dispute. In 2016 a journalistic analysis of COMPAS, a recidivism risk tool, found that Black defendants who did not reoffend were labeled high-risk more often than White defendants who did not (Angwin, Larson, Mattu & Kirchner, ProPublica, 2016); the tool's developer replied that its scores predicted reoffending equally well in both groups (Dieterich, Mendoza & Brennan, Northpointe, 2016). Chouldechova (2017) showed that both statements can hold at once when reoffense rates differ. Kleinberg, Mullainathan & Raghavan (2017) proved a closely related impossibility theorem for risk scores: calibration within groups and balanced average scores among positives and among negatives can all hold together only if the base rates are equal or prediction is perfect.
Opening the black box
Interpretability asks why a model predicts what it does. Two distinctions organize the tools. Global explanations describe the model's behavior overall; local ones explain a single prediction. Intrinsically interpretable models (sparse linear models, short decision trees, rule lists, additive models) are readable as they are; post-hoc methods explain a trained black box from the outside.
| Method | Scope | What it reports |
|---|---|---|
| Permutation importance | global | how much the score drops when one feature's values are shuffled (lesson Feature Importance & Its Pitfalls) |
| Partial dependence (Friedman, 2001) | global | the average prediction as one feature is varied and the others keep their observed values |
| Individual conditional expectation (Goldstein et al., 2015) | local | one partial-dependence curve per example, revealing interactions that averaging hides |
| SHAP (Lundberg & Lee, 2017) | local | additive attributions that sum to the prediction minus its average, built on the Shapley value |
| LIME (Ribeiro, Singh & Guestrin, 2016) | local | the coefficients of a simple model fitted to the black box's outputs on perturbations near the input |
Treat the features as players in a game whose value for a coalition is the expected prediction when the features in are fixed at their values in and the rest are drawn from the data. The Shapley value averages feature 's marginal contribution over all coalitions:
For , the value is , so adding to any coalition changes it by the same amount. The weights sum to one, hence:
The attributions add up to the prediction minus the average prediction, the efficiency property. Note what an attribution is: not the coefficient, but the coefficient times how unusual the feature's value is. With interactions, the joint contribution is split between the interacting features.
from sklearn.inspection import permutation_importance, PartialDependenceDisplay
# Global: score drop when each feature is shuffled, on held-out data
imp = permutation_importance(model, X_val, y_val, n_repeats=10, random_state=0)
for j in imp.importances_mean.argsort()[::-1][:5]:
print(feature_names[j], round(imp.importances_mean[j], 3))
# Global and local: partial dependence with individual (ICE) curves
PartialDependenceDisplay.from_estimator(model, X_val, features=[0, 3], kind="both")Compute importances on held-out data, not on the training set, where an overfitted model "relies" on noise.
Prediction is not intervention
A model trained on observational data estimates : how often the outcome occurs among people who look like . A decision asks something else: what would happen if we set a variable, by treating a patient, changing a price or turning on a sprinkler? The two answers generally differ when a confounder drives both the variable and the outcome. The network below has one: cloudy days make rain likely and make people leave the sprinkler off.
Causal inference makes "what would happen if" precise with potential outcomes: each unit has an outcome under treatment and without it, and only one is ever observed. The average treatment effect is . In a randomized controlled trial a coin decides the treatment , so is independent of and
Without randomization the same difference is biased by whatever makes treated units different. If every confounder is measured, and both treatment values occur at every value of , adjusting for it recovers the effect: . In the network, the grass is wet with probability 92.7% when the sprinkler is seen on and 52.7% when seen off, a gap of 40 points; adjusting for Cloudy gives against , so switching the sprinkler on raises the chance of wet grass by 49.5 points. Confounding had hidden nearly a fifth of the effect.
Think first A hospital's records show that patients who received an aggressive treatment died more often than those who did not. A model trained on these records predicts higher mortality for treated patients. Should the hospital stop the treatment?
Not on this evidence. Doctors give aggressive treatment to the sickest patients, so severity confounds treatment and death ("confounding by indication"). The model correctly predicts that treated patients die more often; it says nothing about what treating a given patient would do. A randomized trial, or an analysis that adjusts for every factor driving both the treatment decision and the outcome, is needed to estimate the effect.
Key takeaways
- Unfairness enters through labels that record past decisions, proxy targets, unrepresentative data and feedback loops; deleting the protected attribute leaves its proxies in place and makes disparities harder to measure.
- Demographic parity equalizes approval rates, equal opportunity true-positive rates, equalized odds both error rates, and calibration the meaning of a score.
- : with unequal base rates and imperfect prediction, equal predictive value and equal error rates cannot coexist, so choosing a criterion is a value judgment.
- Interpretability tools are global or local and intrinsic or post-hoc; for a linear model with independent features, the Shapley attribution is , and attributions sum to .
- Predictive models estimate , not the effect of intervening. Randomization identifies average effects; adjusting for all confounders, , can recover them from observational data.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
A lender wants applicants who would repay to be approved at the same rate in every group, and does not mind if approval rates overall differ. Which criterion is that?
- Demographic parity
- Calibration within groups
- Equal opportunity
- Fairness through unawareness
Show the answer
C. Equal opportunity
Equal opportunity equalizes , the true-positive rate among people who would repay. Overall approval rates can still differ when base rates do.
Two groups have different base rates, and a classifier has the same positive predictive value and the same false-negative rate in both. What follows?
- It also satisfies equalized odds
- Its false-positive rates differ between the groups
- It must be a perfect classifier
- Its approval rates are equal
Show the answer
B. Its false-positive rates differ between the groups
. With PPV and FNR fixed, the FPR is proportional to the odds , so different base rates give different FPRs (unless PPV = 1 or FNR = 1).
A linear model has independent features with and . For the input , what are the interventional Shapley attributions ?
Show the answer
A.
: and . They sum to .
Why does removing the protected attribute from a model's inputs often fail to remove disparities?
- Because models memorize the training labels
- Because other features act as proxies for the attribute, and the labels themselves may encode past disparities
- Because the attribute is still used at test time
- It always succeeds; disparities that remain are statistical noise
Show the answer
B. Because other features act as proxies for the attribute, and the labels themselves may encode past disparities
Correlated features reconstruct the deleted information, and if the labels reflect historical bias, a model that fits them well reproduces it. Removing the attribute also makes disparities harder to measure.
In a randomized experiment, why is the difference in mean outcomes between treated and untreated units an unbiased estimate of the average treatment effect?
- Because randomization makes the sample large
- Because randomization removes measurement error
- Because randomization makes every unit respond the same way
- Because randomization makes treatment independent of the potential outcomes, so
Show the answer
D. Because randomization makes treatment independent of the potential outcomes, so
With independent of , , and likewise for . No confounder can make treated units systematically different from untreated ones.
Go deeper
- Fair Classification · Criteria, impossibility theorems and interventions.
- Interpretability: SHAP, LIME & Their Limits · Explaining predictions, and how explanations can mislead.
- Causal Inference with Machine Learning · Treatment effects, double machine learning and causal forests.
Further reading
- S. Barocas, M. Hardt & A. Narayanan, Fairness and Machine Learning: Limitations and Opportunities (MIT Press, 2023).
- A. Chouldechova, "Fair prediction with disparate impact: a study of bias in recidivism prediction instruments," Big Data 5(2), 153–163 (2017).
- S. M. Lundberg & S.-I. Lee, "A unified approach to interpreting model predictions," Advances in Neural Information Processing Systems 30 (2017).
- G. W. Imbens & D. B. Rubin, Causal Inference for Statistics, Social, and Biomedical Sciences: An Introduction (Cambridge University Press, 2015).