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 positivedemographic_parity_difference(pred, group): the max minus the min positive rate across groupsdisparate_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)