Quest 53 - Bias Detector
Quest 53: Bias Detector
medium 25-30 minutes🎯 Learning Objectives
- How to detect bias in AI outputs using the 4/5ths rule (disparate impact ratio)
- Why measuring rates matters more than measuring counts
- How to calculate per-group fairness metrics
- The critical edge case: different group sizes masking bias
📖 Concept: AI Fairness & Bias Detection
AI models can produce biased outputs — and the bias is often invisible unless you actively measure it. A model might approve 90% of applicants from Group A but only 50% from Group B. If you only look at total counts, this disparity gets hidden behind group size differences.
Fairness in AI is not just an ethical ideal — it’s a measurable property. The most widely used metric is the disparate impact ratio (also called the 4/5ths rule), borrowed from US employment law. If one group’s positive outcome rate is less than 80% of another group’s rate, that’s a signal of potential bias.
Think of bias detection like a dojo instructor watching your form. You might think your technique looks perfect, but the instructor measures the angles and catches the 15-degree deviation you can’t feel. Bias detection tools do the same thing — they measure the numbers your intuition misses.
⚙️ How It Works
The 4/5ths Rule (Disparate Impact Ratio)
Disparate Impact Ratio = min(group_rates) / max(group_rates)If this ratio is < 0.8 (80%), the system is flagged as potentially biased.
Step-by-step calculation
Step 1: Calculate the approval rate per group
// Group A: 10 people, 9 approved → rate = 0.9// Group B: 10 people, 5 approved → rate = 0.5const rateA = approvedA / totalA; // 0.9const rateB = approvedB / totalB; // 0.5Step 2: Compute the disparate impact ratio
const ratio = Math.min(rateA, rateB) / Math.max(rateA, rateB);// 0.5 / 0.9 = 0.555 → biased (below 0.8)Step 3: Flag groups below threshold
const flagged = groups.filter(g => rates[g] < threshold);💡 Example: Different Group Sizes (The Edge Case)
The most dangerous naive-AI mistake: checking raw counts instead of rates.
// ❌ NAIVE: Checks if "approved count" is similarconst approvedA = 9; // Group A: 9 approvedconst approvedB = 1; // Group B: 1 approved// Naive: "9 vs 1 — that's biased!"
// ✅ CORRECT: Checks approval RATES// Group A: 9 out of 10 (90%)// Group B: 1 out of 2 (50%)const rateA = 9 / 10; // 0.9const rateB = 1 / 2; // 0.5const ratio = 0.5 / 0.9; // 0.555 → flaggedWhy rates matter: If Group A has 1,000 people and Group B has 10, comparing raw counts will always make Group B look “underrepresented” — even if both groups have the same approval rate. Rates normalize for group size.
⚠️ Common Mistakes
Mistake 1: Comparing raw counts instead of rates
“Group A has more approvals than Group B — that’s bias!” → Always normalize by group size. A larger group will naturally have more approvals.
Mistake 2: Only checking one direction
“What if Group A is favored over Group B?” → Bias can flow both ways. Check all group pairs.
Mistake 3: Ignoring small sample sizes
“Group C has 1 person who was denied — bias!” → Small samples are noisy. A single denial in a group of 1 doesn’t prove bias. Consider statistical significance.
Mistake 4: Using counts for the disparate impact ratio
“The ratio of 9 approved to 1 approved is 0.11 — that’s biased!” → The ratio must use rates (approved/total per group), not raw counts.
📝 Knowledge Check
📝 Knowledge Check
Q1:What is the 4/5ths rule (disparate impact ratio) used for?
Q2:Why is comparing raw counts (instead of rates) a critical mistake in bias detection?
Q3:Group A: 9 approved out of 10 (90%). Group B: 1 approved out of 2 (50%). What is the disparate impact ratio?
🏋️ Quest: Bias Detector
Now it’s time to practice! Build a bias detection system using fairness metrics.
-
Download the starter files:
Terminal window npx bluebeltdojo download quest-53-bias-detectorcd quest-53-bias-detector -
Open
problem.jsin your editor with your AI tool (Copilot, Claude Code, Cursor, etc.) -
Implement
detectBias(results, demographics)that uses the 4/5ths rule to detect bias -
Important: Pay special attention to the different-group-sizes edge case — naive AI compares counts instead of rates
-
Verify all tests pass:
Terminal window node test.js -
When all tests pass, submit your solution:
Terminal window npx bluebeltdojo submit
💡 Tip: The hardest test case has groups of different sizes. Make sure you calculate rates (approved/total per group), not raw counts.
คำใบ้
- อ่าน instructions ใน
problem.jsอย่างละเอียด - คำนวณ approval rate ต่อกลุ่ม (จำนวน approved / จำนวนทั้งหมด) ไม่ใช่จำนวน raw
- Edge case ที่สำคัญที่สุด: กลุ่มที่มีขนาดต่างกัน — ต้องใช้ rate เทียบกัน
- ถ้าติดขัด ลองอ่าน “Common Mistakes” อีกครั้ง — อย่าดู solution โดยตรง