🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
HTML MASTER CLASS /// LEARN TAGS /// BUILD STRUCTURE /// SEMANTIC WEB /// HTML MASTER CLASS /// LEARN TAGS ///
Total XP: 0|💻 artificialintelligence XP: 0

Measuring Fairness

Master the mathematical definitions of fairness. Explore the trade-offs between Demographic Parity and Equal Opportunity, understand why multiple fairness goals often conflict mathematically, and learn to select the right metric for your specific application domain.

LOADING ENGINE...

Skill Matrix

UNLOCK NODES BY LEARNING NEW TAGS.

Metrics Hub

Quantifying equality.

Quick Quiz //

What does Demographic Parity prioritize?


Fairness isn't a feeling; it's a metric. By formalizing our ethical goals into equations, we can audit and optimize models for objective equality.

1Equal Outcomes

Demographic Parity is a metric that ignores the 'correctness' of a prediction and focuses only on the 'Outcome'. It requires that the probability of a positive outcome (like getting a loan) is the same for all protected groups. This is often used in social policy to ensure that groups that have been historically disadvantaged receive an equal share of opportunities, regardless of current 'eligibility' metrics.

+
// Demographic Parity Concept
function checkDemographicParity(predictions, groups) {
  let rateA = calculatePositiveRate(predictions, groups.A);
  let rateB = calculatePositiveRate(predictions, groups.B);
  
  // P(Y=1 | A) == P(Y=1 | B)
  let disparity = Math.abs(rateA - rateB);
  return disparity <= THRESHOLD;
}
localhost:3000
localhost:3000/parity-check
Demographic Parity Status
Group A Rate: 45%
Group B Rate: 44%
Disparity: 1% (PASS)

2Equal Error Rates

Equal Opportunity focuses on the 'Qualified' individuals. It requires that the True Positive Rate (TPR) is the same across all groups. This means that if you *actually* deserve the loan, the AI should have the same probability of approving you regardless of your group membership. This is often preferred in business contexts because it ensures the model's accuracy is 'Fair' without mandating equal raw outcomes for groups with different base characteristics.

+
// Equal Opportunity Concept
function checkEqualOpportunity(preds, labels, groups) {
  let tprA = calculateTPR(preds, labels, groups.A);
  let tprB = calculateTPR(preds, labels, groups.B);
  
  // P(Y_hat=1 | Y=1, A) == P(Y_hat=1 | Y=1, B)
  let disparity = Math.abs(tprA - tprB);
  return disparity <= THRESHOLD;
}
localhost:3000
localhost:3000/opportunity-check
Equal Opportunity Status
Group A TPR: 90%
Group B TPR: 60%
Disparity: 30% (FAIL)

3The Mathematical Conflict

The Impossibility Theorem of Fairness states that unless the 'Base Rates' (the percentage of true positives) are exactly the same for all groups, you cannot satisfy all fairness metrics at once. For example, if Group A has 10% defaults and Group B has 50% defaults, a model cannot achieve both Demographic Parity *and* Predictive Parity. As an engineer, you must facilitate an Ethical Choice about which form of fairness is most important for your specific user base.

+
// The Impossibility Trade-off
function selectFairnessMetric(policyGoal) {
  if (policyGoal === "EQUAL_REPRESENTATION") {
    return calculateDemographicParity();
  } 
  else if (policyGoal === "ACCURATE_REWARD") {
    return calculateEqualOpportunity();
  }
  // You cannot return both if base rates differ.
}
localhost:3000
localhost:3000/policy-engine
⚠️
Metric Conflict
Select Target Fairness Goal

?Frequently Asked Questions

Pascual Vila

Pascual Vila

Frontend Instructor // Code Syllabus

Lesson Glossary

[01]Demographic Parity

The fairness metric requiring that a positive outcome be granted to all protected groups at the same rate.

Code Preview
Equal Outcomes

[02]Equal Opportunity

The fairness metric requiring that the True Positive Rate be the same for all protected groups.

Code Preview
Equal Merit

[03]Equalized Odds

A stricter metric requiring that both the True Positive Rate and the False Positive Rate be the same for all groups.

Code Preview
Error Equality

[04]Base Rate

The actual percentage of positive cases in a group's true labels (e.g., the actual default rate).

Code Preview
Ground Truth Ratio

[05]False Positive Rate (FPR)

The percentage of negative cases that were incorrectly predicted as positive; often a source of 'Unjust Harm'.

Code Preview
Wrong Accusation

Continue Learning