holisticai.bias.metrics.equal_opportunity_diff#
- holisticai.bias.metrics.equal_opportunity_diff(group_a, group_b, y_pred, y_true)[source]#
Equality of opportunity difference
This function computes the difference in true positive rates for group_a and group_b.
Interpretation
A value of 0 is desired. This metric ranges between -1 and 1, with negative values indicating bias against group_a, and positive values indicating bias against group_b.
Parameters
- group_aarray-like
Group membership vector (binary)
- group_barray-like
Group membership vector (binary)
- y_predarray-like
Predictions vector (binary)
- y_truearray-like
Target vector (binary)
Returns
- float
Equal opportunity difference
Notes
\(tpr_a - tpr_b\)
Examples
>>> import numpy as np >>> from holisticai.bias.metrics import equal_opportunity_diff >>> group_a = np.array([1, 1, 1, 1, 0, 0, 0, 0, 0, 0]) >>> group_b = np.array([0, 0, 0, 0, 1, 1, 1, 1, 1, 1]) >>> y_pred = np.array([1, 1, 0, 0, 1, 1, 0, 1, 1, 1]) >>> y_true = np.array([1, 1, 0, 0, 1, 0, 1, 0, 0, 1]) >>> equal_opportunity_diff(group_a, group_b, y_pred, y_true) 0.33333333333333337