# Fairness and Bias in ML

> Where bias enters ML systems, how to measure group fairness, and what mitigation can and cannot fix. Free notes, key concepts, resources and a mini project.

Canonical: https://www.internhack.in/roadmaps/tracks/machine-learning/fairness
Last updated: 2026-11-28

Where bias enters ML systems, how to measure group fairness, and what mitigation can and cannot fix.

Intermediate · about 5 hours · difficulty 3/5

Learn first: [Evaluation Metrics](https://www.internhack.in/roadmaps/tracks/machine-learning/evaluation-metrics), [Imbalanced Data](https://www.internhack.in/roadmaps/tracks/machine-learning/imbalanced-data)

Models learn from historical data, and history contains unequal treatment. A hiring, lending or healthcare model can quietly reproduce or amplify that. Measuring and addressing it is part of doing the job well, and increasingly a legal requirement.

### Where bias comes from

- **Historical bias**: the labels themselves reflect past unfair decisions.
- **Representation bias**: some groups are under-sampled.
- **Measurement bias**: proxies (arrests for crime, clicks for interest) mean different things for different groups.
- **Proxy features**: removing a protected attribute does not help if postcode or name encodes it.
- **Deployment bias**: using a model in a context it was not built for.

### Measuring it

Always slice metrics by group. Common definitions:

- **Demographic parity**: similar positive prediction rates across groups.
- **Equal opportunity / equalized odds**: similar true positive (and false positive) rates.
- **Calibration within groups**: a score of 0.7 means the same thing for everyone.

These definitions generally **cannot all hold at once**, so choosing one is a value judgement to make with domain experts and affected people, not a purely technical call.

### Mitigation

- **Pre-processing**: better data collection, reweighting.
- **In-processing**: fairness constraints during training.
- **Post-processing**: group-specific thresholds.
- Sometimes the right answer is not to automate the decision at all.

**Fairlearn** and **AIF360** provide metrics and mitigation algorithms.

**Good enough to move on** when you can audit a model's metrics across groups, explain why fairness definitions conflict, and document the trade-off you chose.

## Key concepts

- **Sources of bias**
- **Proxy features**
- **Sliced evaluation by group**
- **Demographic parity and equalized odds**
- **Fairness trade-offs**
- **Mitigation strategies**
- **Fairlearn toolkit**

## Mini project

Train a classifier on the Adult income or a similar public dataset, report metrics by sex and race with Fairlearn, apply one mitigation method, and write up how accuracy and each fairness metric changed.

## Check yourself

Why does deleting the protected attribute column usually fail to make a model fair, and why can demographic parity and calibration conflict?

## Free resources

- [Fairlearn documentation](https://fairlearn.org/) (Fairlearn)
- [Google Machine Learning Crash Course](https://developers.google.com/machine-learning/crash-course) (Google)
- [Fairness and Machine Learning](https://fairmlbook.org/) (Barocas, Hardt, Narayanan)

Previous: [Explainability with SHAP and LIME](https://www.internhack.in/roadmaps/tracks/machine-learning/explainability) · Next: [Privacy and Security in ML](https://www.internhack.in/roadmaps/tracks/machine-learning/privacy-and-security)

## More in Responsible and Trustworthy ML

- [Explainability with SHAP and LIME](https://www.internhack.in/roadmaps/tracks/machine-learning/explainability)
- [Fairness and Bias in ML](https://www.internhack.in/roadmaps/tracks/machine-learning/fairness)
- [Privacy and Security in ML](https://www.internhack.in/roadmaps/tracks/machine-learning/privacy-and-security)
- [Model Cards, Datasheets and Governance](https://www.internhack.in/roadmaps/tracks/machine-learning/model-documentation)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Machine Learning Engineer Roadmap](https://www.internhack.in/roadmaps/tracks/machine-learning)
