Group Fairness Metrics

easy
Unit 7 · Interpretability I0/5 to milestone

A model can be accurate overall and still treat groups very differently. Implement the standard group-fairness metrics for binary predictions pred, true labels y and a group attribute group:

  • positive_rates(pred, group): a dict from group to the fraction predicted positive
  • demographic_parity_difference(pred, group): the max minus the min positive rate across groups
  • disparate_impact(pred, group): the min positive rate divided by the max (the "80% rule" flags values below 0.8). Return 1.0 if every rate is 0.
  • equalized_odds_difference(pred, y, group): the larger of the TPR gap and the FPR gap across groups (each gap is max − min over groups, skipping groups where the rate is undefined)
#fairness#evaluation#responsible-ai2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Group Fairness Metrics · TechGradify