Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

When AI Learns the Wrong Thing: Auditing Name Bias in a Salary Prediction Model

For help with this notebook, contact Dennis Kane dkane@elcamino.edu

AI and Ethics Lab

This lab uses a synthetic dataset containing many different people. Two names are deliberately important:

  • Bob: many people named Bob receive an artificial salary penalty in the historical data, even when their qualifications are similar to other people.

  • Ray: many people named Ray tend to have less experience. Ray receives no direct salary penalty for his name, but will coincidentally have a low salary.

The central question is:

Can an AI learn an unfair relationship from its training data, and how can we audit what the model learned?

Important: The relationships involving names are fictional and were created only for this instructional exercise.

Learning Objectives

By the end of this lab, you should be able to:

  1. Train an AI model to predict a target value, in this case salary.

  2. Use counterfactual testing to investigate a prediction.

  3. Use SHAP to examine feature contributions.

  4. Distinguish a direct unjustified relationship from a correlation involving another explanatory variable.

  5. Explain why an AI explanation does not automatically prove that a decision is fair.

Part 1 — Load the Dataset

In Google Colab, upload bob_ray_salary_data.csv when prompted.

Question 1

Before training the model:

  1. Do candidates named Bob or Ray both appear to have lower average salaries across the dataset? Note that there are many Bobs and Rays in the data.

  2. Does either Bob or Ray also have lower average experience?

  3. Can averages alone prove that an AI model is treating a group unfairly?

Write your answers before continuing.

Part 2 — Train the Salary Prediction Model

The model will initially use all available features, including name.

Mean Absolute Error: $5,668
R² Score: 0.888

Part 3 — Counterfactual Test: Bob vs. John

A counterfactual test changes one thing while holding everything else constant.

Bob and John below have identical qualifications. Only their names differ so the model should predict the same salary.

Bob:  $64,446
John: $84,518
Difference: $20,072

Question 2 — Bob

This Bob and John pair differ only in name.

  1. Did the prediction change?

  2. What evidence does this provide about model behavior?

  3. Is it ethically appropriate for salary prediction to change merely because the subject’s name changed?

Remember: this experiment provides evidence about what the model does. Ethical judgment requires interpretation.

Part 4 — Counterfactual Test: Ray vs. John

Now perform the same test using Ray.

Remember: people named Ray were generated with lower experience on average, but the data-generation formula did not directly subtract money because the subjects are named Ray.

Ray:  $84,379
John: $84,518
Difference: $139

Question 3 — Ray

  1. Did Ray’s name change the prediction?

  2. What relationship exists between Ray and experience in the dataset?

  3. If the model already knows a person’s actual experience, should it also use the name as a statistical shortcut for experience?

This is the key distinction between the Bob and Ray cases.

Part 5 — SHAP: What Does the Model Say Influenced Its Prediction?

Important Ethical Distinction

SHAP reveals how a model makes predictions, but interpretability alone does not establish whether a model is fair or unfair.

SHAP helps answer:

Which features contributed to this prediction?

It does not, by itself, answer:

Was this prediction ethically justified?

We will use SHAP together with counterfactual testing.

<Figure size 800x950 with 1 Axes>

Question 4 — Global SHAP Results

  1. Are name-related features important to the model?

  2. Is experience important?

  3. What does feature importance tell you?

  4. What can feature importance not tell you about fairness?

Part 6 — Individual SHAP Explanations

Now examine Bob, Ray, and John individually.

Bob Test Profile
<Figure size 800x750 with 3 Axes>
Ray Test Profile
<Figure size 800x750 with 3 Axes>
John Test Profile
<Figure size 800x750 with 3 Axes>

Question 5 — What Did SHAP Add?

Compare the two audit methods.

Counterfactual testing asks:

What happens if I change one feature?

SHAP asks:

How did the model attribute this prediction among its features?

Discuss:

  1. What did SHAP reveal about subjects named “Bob?”

  2. What did SHAP reveal about subjects named “Ray?”

  3. What information did counterfactual testing provide?

  4. Could either technique be misleading if used alone?

Part 7 — Remove Names and Retrain

Now audit whether the model really needs access to names.

MODEL WITHOUT NAME
Mean Absolute Error: $8,061
R² Score: 0.772
Prediction when the model cannot see the name: $81,056

Part 8 — Final Ethical Audit

Write a short analysis.

1. Bob

What evidence suggests that the model learned an unjustified relationship involving subjects named “Bob?”

Use both counterfactual and SHAP evidence.

2. Ray

Why is evaluating the salary of someone named “Ray” more complicated?

Discuss the difference between:

  • the name itself

  • actual experience

  • a statistical shortcut

3. SHAP

Was SHAP useful?

What could it tell you?

What could it not tell you?

4. The Larger Ethical Question

Does a highly accurate AI model automatically become ethical to use for salary, hiring, promotion, or other high-stakes decisions?

Why or why not?

Key Concept

Explanation is not justification.

An AI can explain:

Why it made a prediction

without proving:

The prediction was fair, appropriate, or ethically justified.

Responsible AI auditing may combine:

  • examination of training data

  • counterfactual testing

  • model explanations

  • outcome analysis

  • ethical and human judgment