AI BIAS
Artificial intelligence can feel almost magical. It powers search, recommends movies, analyzes documents, and even assists in medical decisions. But there is a major challenge that is easy to overlook: bias. AI bias occurs when a system treats some groups unfairly, often in subtle ways.
A simple example
Imagine training a hiring model using examples from past company decisions. If most of the people hired were men, the model may learn that men are more likely to be selected. It can then recommend men more often, even when qualified women are available. That is AI bias in action.
AI learns from historical data, and that data often reflects human bias. Bias can come from incomplete, skewed, or poorly designed datasets. If left unchecked, biased models can harm people during important decisions such as lending, hiring, and healthcare.
Why Should We Care?
Fairness: People deserve equal treatment regardless of race, gender, or age.
Legal concerns: Regulations such as Title VII and the GDPR require organizations to prevent discriminatory outcomes.
Better performance: Fairer models often turn out to be more accurate and useful for everyone.
How Do We Fix AI Bias?
A paper titled
“Bias Mitigation Methods: Applicability, Legality, and Recommendations for Development”
by Suresh and Guttag outlines three broad strategies for reducing bias:
1. Pre-Processing
Clean, rebalance, or transform the data before training. For example, you can reweight underrepresented groups so the model sees enough examples of them.
2. In-Processing
Modify the learning process itself. One approach is adding a fairness penalty to the loss function during training so the model avoids overly biased patterns.
3. Post-Processing
Adjust model outputs after training. You might change decision thresholds for different demographic groups to reduce unfair disparities.
“We group bias mitigation techniques into three main categories, each operating on a different slice of the machine learning pipeline.”
Suresh & Guttag, Section 3
Where Bias Comes From
Bias can appear at many points in an AI pipeline. Data collection may overlook entire populations. Features may indirectly encode sensitive traits. A training algorithm may reward patterns that look predictive but reinforce historical inequality. The paper emphasizes that bias is not only technical. It is legal, social, and ethical.
Key considerations:
Some laws restrict collecting protected attributes, which complicates fairness work.
In some cases, removing these attributes entirely can make bias harder to detect.
Fixing bias can itself create legal risks if the methods treat protected groups differently.
Code Example: A Simple Fairness Penalty
The example below illustrates, in a simplified way, how an in-processing fairness penalty can be added to logistic regression. It focuses on a concept called demographic parity, which checks whether groups receive positive outcomes at similar rates.
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
# 1. Create Fake Data
N = 200
np.random.seed(42)
# Suppose half our samples belong to a sensitive group = 1, others = 0
sensitive_attr = np.random.binomial(1, 0.5, N)
X = np.random.randn(N, 3) + sensitive_attr[:, None] # Shift distribution
y = (X[:, 0] + X[:, 1] + 0.5*sensitive_attr + np.random.randn(N)*0.5 > 0).astype(int)
X_train, X_test, y_train, y_test, s_train, s_test = train_test_split(
X, y, sensitive_attr, test_size=0.3, random_state=42
)
# 2. Standard Logistic Regression
clf = LogisticRegression(solver='liblinear')
clf.fit(X_train, y_train)
y_pred_standard = clf.predict(X_test)
acc_standard = accuracy_score(y_test, y_pred_standard)
# Demographic Parity: difference in positive outcome rates between groups
def demographic_parity_difference(y_pred, sensitive):
group0_mean = np.mean(y_pred[sensitive == 0])
group1_mean = np.mean(y_pred[sensitive == 1])
return abs(group0_mean - group1_mean)
dp_diff_standard = demographic_parity_difference(y_pred_standard, s_test)
print("Standard Model Accuracy:", acc_standard)
print("Standard Model Demographic Parity Difference:", dp_diff_standard)
# 3. In-Processing: Add a Fairness Penalty
weights = np.zeros(X_train.shape[1])
bias = 0.0
lr = 0.01
lambda_fair = 0.5 # weight for fairness
def sigmoid(z):
return 1 / (1 + np.exp(-z))
for epoch in range(200):
z = np.dot(X_train, weights) + bias
preds = sigmoid(z)
error = preds - y_train
# Standard logistic regression gradients
grad_w = np.dot(X_train.T, error) / len(X_train)
grad_b = np.mean(error)
# Demographic Parity "penalty"
preds_bin = (preds >= 0.5).astype(int)
dp_diff = demographic_parity_difference(preds_bin, s_train)
# Naive fairness adjustment for demonstration
weights -= lr * (grad_w + lambda_fair * dp_diff)
bias -= lr * (grad_b + lambda_fair * dp_diff)
# Evaluate fairness-penalized model
z_test = np.dot(X_test, weights) + bias
test_preds = (sigmoid(z_test) >= 0.5).astype(int)
acc_fair = accuracy_score(y_test, test_preds)
dp_diff_fair = demographic_parity_difference(test_preds, s_test)
print("Fairness-Penalized Model Accuracy:", acc_fair)
print("Fairness-Penalized Model DP Difference:", dp_diff_fair)
What the Code Does
Creates a small synthetic dataset with one sensitive attribute.
Trains a standard logistic regression model and measures its fairness.
Trains a second model with a simple fairness penalty that encourages more equal treatment across groups.
This is a toy example. Real production systems typically use libraries like Fairlearn or AIF360 and far more rigorous evaluation methods.
Important Details from the Paper
Fairness is a trade-off: Increasing fairness may reduce accuracy for some groups or the overall model.
Legal constraints matter: Some fairness methods may not be allowed in certain jurisdictions.
No universal definition of fairness: Different metrics suit different contexts.
“Combining pre-processing and in-processing strategies can improve fairness across multiple metrics, although it may affect overall model performance.”
Suresh & Guttag, Section 5
How to Apply These Ideas in Practice
Audit your data for missing or biased representation.
Define your fairness goal and choose metrics that match it.
Experiment with multiple mitigation strategies to find the best fit.
Review legal requirements before deploying any fairness solution.
Monitor the model over time, since real-world drift can reintroduce bias.
Recommended Resources
Algorithmic Justice League: Stories and advocacy around AI harm.
AI Now Institute: Research on law, society, and technology.
Fairlearn and AIF360: Open-source tools for fairness evaluation and mitigation.