Expert: deep learning and AI · Ethics, privacy and careers · topic 58 of 62 · 35 min
Bias and fairness
Explanation
Why fairness is a data problem
Models learn patterns from data, and data records the past, including its unfairness. If a company hired fewer women for engineering roles in the past, a model trained on those decisions may learn that being a woman lowers the chance of being hired. Nobody wrote that rule; the model found it. Because ML decisions now affect loans, jobs, insurance and access to services, checking for unfair outcomes is part of a data professional's job.
Where bias comes from
- Historical bias: the world itself was unequal, and the labels reflect it.
- Sampling (representation) bias: some groups are missing or rare in the data, such as rural users in an app that launched in cities, so the model works worse for them.
- Label bias: the "right answers" were produced by people or processes with their own biases.
- Measurement bias: a feature is measured worse for some groups (for example, cheaper phones taking poorer photos).
- Proxy features: even if you drop gender or caste, other columns such as pin code, first name, college or language can stand in for them.
Measuring fairness: simple metrics
Start by computing outcomes per group. The selection rate is the share of each group that gets the positive decision (approved, shortlisted). Demographic parity asks whether selection rates are similar. The disparate impact ratio divides the lowest group's selection rate by the highest; the "four-fifths rule" from US hiring guidance treats a ratio below 0.8 as a warning sign. It is a rule of thumb, not proof of discrimination or a legal standard everywhere.
decisions = [1, 1, 0, 1, 0, 1, 0, 0, 0, 1]
groups = ["A", "A", "A", "A", "A", "B", "B", "B", "B", "B"]
rate = {}
for g in set(groups):
picked = [d for d, gg in zip(decisions, groups) if gg == g]
rate[g] = sum(picked) / len(picked)
print(sorted(rate.items()), round(min(rate.values()) / max(rate.values()), 2))Equal opportunity looks at errors instead: among people who truly qualify (true label 1), is the true positive rate similar across groups? A model can have equal selection rates and still miss qualified people in one group much more often. Different fairness definitions can conflict with each other, so teams must choose, with legal and domain advice, which matters most for the decision at hand.
Reducing unfairness
- Better data: collect more examples from under-represented groups; fix biased labels.
- Remove or test proxy features, and check results per group after every change.
- Reweight or resample training data so groups count fairly.
- Review thresholds per decision with domain experts and legal advice.
- Keep humans in the loop for high-stakes decisions, with a way for people to appeal.
- Document the model (a "model card"): what it is for, what data it used and how it performs for each group.
Common mistakes
- Believing that dropping a sensitive column makes a model fair. Proxies remain.
- Reporting only overall accuracy, which hides poor performance for small groups.
- Checking fairness once before launch and never again.
Need help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
Bias and fairness · 1/7
Models learn from past data, and past data can be unfair. So models can be unfair too.
Prefer a video by a teacher? Find free videos on “algorithmic bias fairness in machine learning explained disparate impact” on YouTube ↗
In real life: A hiring screen that learned the wrong lesson
Public reports have described resume-screening tools that, trained on years of past hiring, learned to rate resumes lower when they contained signals linked to women, such as women's college names or clubs. The lesson for any company in India building a campus-hiring screen: test selection rates and error rates by gender, college tier and region before use, look for proxy features, and keep a human decision-maker accountable.
Practice (0/3 done)
Write selection_rates(decisions, groups) where decisions are 0/1 and groups are labels of the same length. Return a dict mapping each group to its share of 1 decisions, rounded to 4 decimal places.
Write disparate_impact(rates) where rates is a dict of group → selection rate. Return a tuple (ratio, passes): ratio = lowest rate / highest rate rounded to 4 decimal places, and passes = ratio >= 0.8. If the highest rate is 0, return (1.0, True) (nobody is selected, so no group is favoured).
Write tpr_by_group(y_true, y_pred, groups): for each group, the true positive rate = (cases with y_true 1 AND y_pred 1) / (cases with y_true 1), rounded to 4 decimal places. Groups with no true positives cases get None.
Quick quiz
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- Privacy and data protectionEthics, privacy and careers · same module
- Career paths: analyst, scientist, ML engineer, AI engineerEthics, privacy and careers · same module
- Portfolio, projects and interviewsEthics, privacy and careers · same module
- Overfitting, underfitting and regularisationEvaluating models
- Probability basicsProbability and inference
- Core DevOps practices and the DORA metricsDevOps: Git, Docker, Kubernetes and CI/CD · DevOps culture and the SDLC
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
A model never sees the "gender" column but still treats women unfairly. What is the most likely reason?
Answer: Other features act as proxies for gender
Names, colleges, clubs or job titles can carry the same information.
Group A is approved 50% of the time and group B 30%. What is the disparate impact ratio?
Answer: 0.6
0.30 ÷ 0.50 = 0.6, below the 0.8 rule of thumb.
What does "equal opportunity" compare across groups?
Answer: The true positive rate among people who truly qualify
It asks whether qualified people are found equally often.
A voice assistant works worse for rural accents because training audio came mostly from cities. This is…
Answer: Sampling (representation) bias
Some groups were under-represented in the data.
Which practice best supports fairness after launch?
Answer: Monitor outcomes and errors per group regularly, with a way to appeal decisions
Fairness can drift as data and users change.
Your model is only slightly better than the simple rule. What should the write-up say?Related
Answer: Report both honestly and discuss whether the extra complexity is worth it
Honest comparison is a strength in a portfolio.
Which is an embedded feature-selection method?Related
Answer: Lasso pushing weights to zero
Selection happens during model training.
Why monitor a model after deployment?Related
Answer: Because the data and the world change, so accuracy can drop over time
New cities, prices or user habits can make an old model wrong.
A model scores 0.60 on training and 0.58 on validation for a task where 0.90 is achievable. It is…Related
Answer: Underfitting
Low scores on both mean the model is too simple or lacks good features.
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- 4 more topics in “Ethics, privacy and careers” before its exam: Privacy and data protection, Career paths: analyst, scientist, ML engineer, AI engineer, Portfolio, projects and interviews, Capstone: an end-to-end project.
- Module 12 exam: Ethics, privacy and careers · 12 questions · 20 min, without help. 5 topics of this module still to finish first.
- 62 topics left in the course before the final exam.