Skip to chapter content
navan✳THE BUILD LABMACHINE LEARNING / GUIDE
0/28 read
CHAPTER 26 / 28 · RESPONSIBLE SYSTEMS

Fairness, bias, and cause.

Understand how labels and sampling can encode unequal outcomes and why prediction differs from intervention.

BY NAVAN SAMILONG READTHEORY FIRST
01 / FROM THE BEGINNING

Start with the meaning.

A model learns from recorded examples, including the limits and historical decisions inside them. If a lending dataset records approvals made under an unequal policy, learning to reproduce those approvals can reproduce the policy rather than predict a person's true ability to repay. A feature can also act as a proxy for a protected characteristic even when that characteristic is removed. Fairness cannot be obtained by deleting one column and assuming the remaining data is neutral.

Selection bias appears when only some outcomes are observed. A hiring model may know job performance only for applicants who were hired, not those who were rejected. The dataset cannot directly tell us how rejected people would have performed. A high validation score on the observed group does not repair the missing counterfactual. The collection process, target definition, and use of predictions must be part of the analysis.

02 / THE MODEL

How the idea works.

Fairness has several possible meanings. Equal error rates across groups, equal selection rates, and equally calibrated probability estimates are different goals that may conflict when group base rates differ. A metric choice expresses values about which harms matter and who bears them. Report outcomes and error types by relevant groups where it is lawful and appropriate, while protecting privacy and avoiding tiny groups that make estimates unstable.

Causality asks what would happen if an action changed. Prediction asks what outcome is likely given observed information. The two can diverge. A model may predict high hospital use from a feature that marks poor access to preventive care. Removing that feature from the input or acting on it may have very different consequences from what a coefficient suggests. Controlled experiments, natural experiments, and causal assumptions address intervention questions; a predictive model alone does not.

Human oversight is not automatically effective. A person who sees a confident model score may defer to it without independent review. A useful oversight process defines what information reviewers see, when they can override a model, how disagreements are recorded, and how affected people can correct errors. The model should support a decision process whose objectives and responsibilities are explicit.

03 / PYTHON, EXPLAINED

Follow the code.

fairness-and-causality.py
from sklearn.metrics import confusion_matrix

records = [
    {"group": "A", "actual": 1, "predicted": 1},
    {"group": "A", "actual": 1, "predicted": 0},
    {"group": "B", "actual": 1, "predicted": 0},
    {"group": "B", "actual": 0, "predicted": 0},
]
for group in ["A", "B"]:
    subset = [row for row in records if row["group"] == group]
    print(group, confusion_matrix(
        [row["actual"] for row in subset],
        [row["predicted"] for row in subset], labels=[0, 1]
    ))

The records pair actual and predicted labels with a group name. A list comprehension selects rows for one group, and confusion_matrix counts errors within that subset. The labels=[0, 1] argument keeps both classes in the output even if a tiny subset lacks one class. Group A has one true positive and one false negative; group B has one true negative and one false negative. These four rows are far too few to compare group performance reliably, but the code shows the kind of disaggregation an overall score can hide.

The group labels here are placeholders. In a real setting, group definitions, permissions, privacy, sample sizes, and the purpose of analysis require care. A difference in observed errors is a signal to investigate data and decision pathways, not by itself an explanation of its cause.

04 / THE BOUNDARY

What the result does not say.

A model can create feedback loops. If a system directs attention to cases it already predicts as risky, those cases may be observed more often, and future training data may reflect the model's own choices. Later scores can look self-confirming. Recording who was exposed to which action helps distinguish model behavior from the underlying world.

Meaningful fairness work starts before fitting, with the task's purpose and the costs of mistakes. It continues after deployment through monitoring, correction, and accountability. It is not one library metric appended at the end.

05 / KEEP THIS

One clear idea.

A predictive pattern can reflect unequal history or sampling; fair use requires examining the whole decision process.

THE CODE IN CONTEXT

The ML cookbook

Complete, explained Python workflows sit alongside this reading course.

Browse the cookbook
Finished reading?
Built with curiosity. By Navan Sami. ↗Machine learning with Python · From examples to trustworthy models.