โ†
AI for Tech Certification
Aware ยท M7 ยท lesson 7 of 22 ยท queued
Preview โ€” browse every lesson free. Enroll to mark lessons complete, open partner links and save your progress. Login & enroll โ†’
Bias in Code: How AI Systems Inherit and Amplify Problems
๐Ÿ“–
now learning

Bias in Code: How AI Systems Inherit and Amplify Problems

15 min

How Machines Learn Human Prejudice

You're building a hiring algorithm. You want to be objective. You train a model on historical hiring data: who was hired, who wasn't. The model learns patterns that predict hiring.

The problem: Your historical hiring data encodes human prejudice. Women were hired less frequently. So the model learns: "Applications from women are less likely to be hires." This isn't because the model is biased (models aren't biased; they're neutral). It's because the training data is biased.

Now you deploy the model. It systematically disadvantages women applicants. You didn't write code to discriminate. You just fed the model biased data.

This is the insidious part of AI bias: it's learned, not coded. It's not intentional. Yet it causes real harm.

How Bias Gets In: Five Pathways

1. Historical Bias: The Past Predicts Unfairly

Past discrimination gets encoded in data. Your hiring data: women were hired 10% of the time. Model learns this and predicts women are 10% likely to be good hires (controlling for everything else). It perpetuates past discrimination.

More subtle: hiring data includes performance ratings. Past managers rated women lower (conscious or unconscious bias). Model learns that the same performance metrics predict lower outcomes for women.

Historical bias is hard to fix because it's baked into the data. You can't just remove women from training data (that makes it worse). You have to actively rebalance the data or use fairness constraints to overcome it.

2. Representation Bias: Not Everyone's Equally Represented

Your training data comes from one source. Say, hiring data from tech companies in Silicon Valley. The data is primarily white, male, working-age engineers.

You train on this data. Model learns patterns that apply to this demographic. You deploy to hire across diverse candidates. Model performs 95% accurately on white males, 75% accurately on women and minorities.

Why? The model never learned patterns from these other groups. It extrapolates from what it knows (white male patterns), which don't generalize.

3. Measurement Bias: Bad Metrics Bake in Bias

You're training a model to predict "good employee." You measure this as: performance rating given by manager.

Problem: Manager ratings are biased. Managers rate people like them more favorably. They're harder on people from different backgrounds. The "good employee" metric is actually "person who manager liked."

Model trained on biased metrics learns the bias. It doesn't learn what makes a good employee. It learns what makes a manager like someone.

4. Aggregation Bias: One Model for All Hides Group Differences

You build one model to predict outcomes for all groups. The model optimizes for overall accuracy.

Problem: What's optimal for one group might hurt another. A high threshold for hiring might be good overall (fewer false positives) but disproportionately hurts a minority group that has higher variance in the training data.

Different groups might need different thresholds. Aggregating into one model hides this.

5. Evaluation Bias: Testing on Unrepresentative Data

You test your model on evaluation data. It performs 95% accurately. You think it's good. You deploy.

In production, it performs 75% accurately. Why? Your evaluation data wasn't representative. It was similar to training data (same demographic distribution, same data sources).

When deployed to real-world data (which is more diverse), performance drops. You didn't see this in evaluation because you didn't test on diverse data.

Bias is Invisible at Aggregate Level: A system that performs 95% accurately overall might perform 75% accurately on one demographic group. If you only look at overall accuracy, you completely miss the bias. This is why stratified evaluation is essential. You have to disaggregate results by demographic group to see the bias.

Amplification: Feedback Loops That Make Bias Worse

Bias in training data is bad. But feedback loops make it worse.

Scenario: Your lending algorithm is trained on historical data. It shows 10% bias against minorities (approves them less frequently).

You deploy it. Now it approves loans less frequently to minorities. Fewer minorities get loans. This becomes next month's data.

You retrain on new data. New data has even less minority success (because the algorithm created that). New model learns stronger bias.

Over months, the feedback loop amplifies bias. Initial 10% bias becomes 15%, then 20%. Your system becomes increasingly discriminatory not because you changed anything, but because the feedback loop amplifies.

This is particularly dangerous in hiring, lending, and criminal justice, all domains with strong feedback effects.

Real-World Harms: Documented Cases

This isn't theoretical speculation. These are documented, real-world harms:

Amazon's Hiring Algorithm: Built to select talent. Trained on historical hiring data. Model learned to disadvantage women. Amazon had to scrap it.

Facial Recognition: Early facial recognition systems had 1% error rate on white faces, 34% error rate on dark-skinned faces. This affected law enforcement (wrong arrests) and security systems (minorities were wrongly denied access).

Healthcare Algorithm: Algorithm predicted patient health risk. Black patients were systematically rated as lower risk than white patients with same medical history. This led to under-treatment because the algorithm said they needed less intensive care.

COMPAS (Criminal Risk Assessment): Algorithm predicted recidivism (whether released prisoners would reoffend). False positive rate for Black defendants: 45%. False positive rate for white defendants: 23%. Algorithm recommended harsher sentences for minorities.

Lending and Credit: Multiple studies found lending algorithms charge higher interest rates to minorities with same creditworthiness as whites. This is discrimination, even if unintentional.

Each of these was built by well-intentioned engineers. None of them wrote code saying "discriminate against minorities." The bias came from data, and it went undetected until real-world harm occurred.

Detecting Bias: Disaggregated Evaluation

You can't detect bias by looking at aggregate metrics. You have to disaggregate.

Process:

  • Identify demographic groups: What groups matter? (race, gender, age, location, etc.) Depends on your domain and what's legally protected.
    - Split test data by group: Separate your evaluation data by demographic group.
    - Evaluate separately: Run the model on each group. Calculate metrics for each group separately.
    - Compare metrics: Are the metrics equal across groups? If not, you have bias.

Metrics to compare:

  • Accuracy: Does the model perform equally well for all groups? Hiring algorithm should have similar accuracy across genders/races.
    - False positive rate: How often does the model incorrectly predict positive for negative cases? In criminal justice, false positives disproportionately harm minorities (incorrect convictions). Rates should be equal across groups.
    - False negative rate: How often does the model incorrectly predict negative for positive cases? In hiring, false negatives mean qualified candidates aren't hired. Rates should be equal across groups.
    - Precision: When the model predicts positive, how often is it correct? In ranking (e.g., "rank these candidates"), precision determines whose candidates make it to top of list. Precision should be equal across groups.
    - Calibration: Does the model's confidence match reality? For a prediction of "70% likely," does outcome happen 70% of the time across all groups?

Red flags:

  • Accuracy varies >5% across demographic groups
    - False positive rates vary by >10% across groups
    - Different groups have different optimal thresholds (e.g., 50% confidence for one group, 70% for another)
    - Model performs well on majority group but poorly on minority group

Mitigating Bias: Technical and Organizational Approaches

1. Audit Training Data

Before training: Who's represented in your data? Check demographic distributions. Are you missing entire groups? Do some groups have different data quality?

Example: Your medical data might have more comprehensive records for one group (because they have better healthcare access historically) and sparser records for another. This creates an unfair comparison.

Look for patterns: How were outcomes measured? Are there reasons to think measurement bias exists?

2. Diversify Training Data

Explicitly collect data from underrepresented groups. If your data is 80% male, work to collect more female representation. This costs effort but is necessary.

3. Stratified Evaluation

Test performance on each demographic group separately. Not just overall accuracy. Track metrics per group.

4. Fairness Constraints During Training

During model training, add explicit fairness objectives. "Optimize for accuracy, but subject to constraint: false positive rate must be equal across genders."

This might reduce overall accuracy (tradeoff), but ensures fairness. Leadership has to accept this tradeoff.

5. Human Review for High-Stakes Decisions

For consequential decisions (hiring, lending, criminal sentencing), don't rely on the model alone. Have human review, especially for edge cases and demographic patterns.

6. Continuous Monitoring

Monitor in production for bias. Track decisions by demographic group. If bias emerges (feedback loops might create it), retrain and fix.

7. Transparency and Disclosure

Tell users how the algorithm works, what its limitations are, and how demographic groups are affected. "This model has 5% error rate overall, but 8% for group X. Here's why..." Transparency builds trust and allows for external scrutiny.

The Leadership Question: Can You Accept Lower Accuracy for Fairness?

Here's where bias mitigation becomes organizational, not just technical.

Suppose you build a hiring algorithm. Unconstrained optimization: 95% overall accuracy. But accuracy is 90% for women, 95% for men.

To make it fair (equal accuracy for both genders), you add fairness constraints. New model: 92% for women, 92% for men. Overall accuracy drops to 92%.

Leadership has to choose: Is 95% overall accuracy with unfairness acceptable? Or is 92% overall with fairness better?

The right answer (almost always): fairness is better. Here's why:

  • Legal risk: Biased systems can face discrimination lawsuits. Unfairness is expensive.
    - Reputation damage: Discovered bias damages reputation. Users/employees lose trust.
    - Fairness is right: Biased decisions harm people. That's worth the 3% accuracy loss.

But not all organizations see it this way. Some optimize for accuracy and ignore fairness until forced to by law or scandal.

As a CTO, you can advocate for fairness. Push for it. But ultimately, it's a leadership decision about what the organization values.

What Comes Next

The next lesson is about accountability: when AI systems cause harm, who's responsible? What's the legal and ethical framework?

Case Study: Credit Lending Bias Detection and Remediation

A fintech company built a credit approval model. They trained it on 500K historical loan applications: approved/rejected decisions, applicant demographics, credit metrics. The model achieved 92% accuracy on test data.

One year in production, serving 10K applications/month, they audited for bias. They ran stratified evaluation:

Results by Demographic Group:

  • White applicants: 92% approval rate (model says "approve" 92% of time)
    - Asian applicants: 88% approval rate
    - Hispanic applicants: 84% approval rate
    - Black applicants: 78% approval rate

Same credit metrics, same income, but different approval rates by race. This is statistical discrimination, the model learned to penalize being a minority.

Root Cause Investigation:

They examined the training data. Historical approval rates in the data reflected real-world lending bias (banks approved white applicants at higher rates than minority applicants). The model learned this pattern perfectly. It's a faithful representation of historical bias, encoded into the model.

Secondary Issue: Measurement Bias

They looked at the features more carefully. One feature: "primary residence zip code." Another pattern: minority applicants' zip codes had different average home values. The model learned: lower zip code home values = higher rejection. This is a proxy for race.

Mitigation Plan (3-Month Program):

Month 1: Understanding the Tradeoff

Leadership question: "Can we accept lower accuracy to achieve fairness?" The analysis showed: to make approval rates equal across races (equalized odds fairness), they'd need to reduce overall accuracy from 92% to 89% (3% loss). They'd have to approve some riskier applicants from underrepresented groups and reject some safer applicants from overrepresented groups.

Leadership decided: "Fairness is more important. We'd rather approve some marginal applicants from minorities than perpetuate historical bias. The 3% accuracy loss is worth it."

Month 1-2: Technical Mitigation

They implemented fairness constraints in model training. Instead of optimizing for accuracy alone, they added a fairness objective: "Minimize approval rate differences across races." They used a technique called "adversarial debiasing": trained a second model to predict race from model outputs, then penalized the main model if it was too predictable. This forced the main model to make decisions independent of race.

Result: approval rates became equal across races (87%, 86%, 87%, 86%), but overall accuracy dropped to 89%.

Month 2: Feature Engineering

They re-examined features. They removed the "zip code" feature (too correlated with race). They examined all other features for proxy correlations. They added new features: credit score trend (is the applicant improving?), payment history stability (consistent vs erratic). These features are more predictive and less biased.

New model: accuracy back to 91%, approval rates equal across races.

Month 2-3: Human Review

For edge cases (borderline applications), they added human review. The model would flag: "I'm uncertain about this one. Recommend human review." A loan officer would look at the application with explicit instructions: "Review for fairness. Don't let demographic factors influence your decision." This catch layer reduced bias further (human review is better at context).

Month 3: Monitoring and Remediation

They set up continuous monitoring: monthly audits of approval rates by race. They created remediation process: if bias emerges, immediate investigation + retraining.

They also audited historical decisions. Analyzed 10K applications approved/rejected in the previous year. Estimated: 200-300 applicants were likely unfairly rejected due to bias (minority applicants with credit metrics similar to approved white applicants). They reached out to these applicants, offered to reconsider their application. Offered $250K in loans to rectify past bias. This was expensive but important for restoring trust.

Outcomes:

  • Model accuracy: 92% โ†’ 91% (acceptable tradeoff)
    - Approval rate disparity: 14 percentage point gap (92% white, 78% Black) โ†’ 1 percentage point (87%, 86%, 87%, 86%)
    - Business impact: slightly more defaults (3% higher loss rate), but offset by improved reputation and reduced legal risk
    - Legal/regulatory: proactive approach meant no lawsuits or regulatory action
    - Long-term: more stable company, better brand reputation, better talent attraction (people want to work on ethical AI)

Key Lessons:

  • Bias isn't malicious, but it's real. Nobody set out to discriminate. The model faithfully learned historical bias. That doesn't make it acceptable.
    - Fairness requires proactive audit. They didn't catch this by looking at overall metrics. They had to disaggregate by race.
    - Fairness has costs, but so does bias. The 3% accuracy loss was far cheaper than the legal risk and reputation damage of continuing with a biased system.
    - Remediation includes past harm. Once you discover bias, you have moral and legal obligation to consider remedying harm to previous victims.
    - Fairness is ongoing. This wasn't a one-time fix. Monthly audits keep the system honest.

What to Do Monday Morning

  • For each AI system in production that makes decisions affecting people, audit the training data: who's represented? Who's missing?
    - Run stratified evaluation: test performance on each demographic group separately. Look for disparities.
    - If disparities exist, decide: is this acceptable? If not, design mitigation (data rebalancing, fairness constraints, human review).
    - Set up continuous monitoring: track decisions by demographic group in production. Alert if bias emerges.
    - Create a fairness policy for your organization: what level of fairness is required? Who approves decisions to trade off accuracy for fairness?

Key Insight

AI systems learn biases from training data automatically and unconsciously. Bias is amplified by feedback loops. Detecting bias requires stratified evaluation. Mitigating bias requires data work, fairness constraints, and human review. Organizations that ignore bias risk lawsuits, reputation damage, and real harm to users. Fairness is worth the effort.

Frequently Asked Questions

If we optimize for fairness over accuracy, won't we get worse results?

Yes, usually. Fairness has a cost in pure accuracy. But that cost is worth it because: fairness is ethically right, unfairness causes harm, biased systems have legal risk. The question isn't "fairness or accuracy" but "is 1-3% accuracy loss worth the fairness?" Answer for most domains: yes.

How do we know what demographic groups to test for bias?

Legally protected classes (race, gender, age, national origin, disability status) are typical. Beyond that, depends on your domain. In hiring: test gender, race, age. In healthcare: race, gender, age, location (healthcare access varies geographically). In credit: income level, location, age. Think about what groups are historically disadvantaged in your domain.

Is bias in AI data fundamentally unsolvable?

No, but it requires effort. You can't eliminate bias (training data always has some), but you can reduce it to acceptable levels with: diverse data, careful measurement, fairness constraints, human review, monitoring. It's work, but doable.

What if we discover bias after deploying?

Quick response: stop using the biased system for high-stakes decisions immediately. Retrain with fairness constraints. Audit historical decisions made by the biased system (were they unfair?). Potential remediation if harm occurred. This is why monitoring is important.

Doesn't fairness mean identical outcomes?

No. Fairness has many definitions. Demographic parity (equal representation). Equalized odds (equal false positive/negative rates). Calibration (equal confidence-to-outcome mapping). Individual fairness (similar people treated similarly). Different domains need different definitions. Think carefully about what fairness means for your use case.

On This Page

How Machines Learn Human Prejudice
How Bias Gets In
Amplification
Real-World Harms
Detecting Bias
Mitigating Bias
The Leadership Question
Case Study: Credit Lending
Monday Morning Action


Chapter Details