holisticai.bias.metrics.multiclass_statistical_parity#
- holisticai.bias.metrics.multiclass_statistical_parity(p_attr, y_pred, groups=None, classes=None, aggregation_fun='mean')[source]#
Multiclass statistical parity
This function computes statistical parity for a classification task with multiple classes and a protected attribute with multiple groups. For each group compute the vector of success rates for entering each class. Compute all distances (mean absolute deviation) between such vectors. Then aggregate them using the mean, or max strategy.
Interpretation
The accepted values and bounds for this metric are the same as the 1d case. A value of 0 is desired. Values below 0.1 are considered fair.
Parameters
- p_attrarray-like
Multiclass protected attribute vector.
- y_predarray-like
Prediction vector (categorical).
- groupslist, optional
Unique groups from p_attr in order
- classeslist, optional
The unique output classes in order
- aggregation_funstr, optional
The function to aggregate across groups (‘mean’ or ‘max’)
Returns
- float
Multiclass Statistical Parity
Examples
>>> import numpy as np >>> from holisticai.bias.metrics import multiclass_statistical_parity >>> p_attr = np.array(["A", "A", "A", "A", "B", "B", "B", "B", "C", "C"]) >>> y_pred = np.array([0, 1, 2, 0, 1, 2, 0, 1, 2, 0]) >>> y_true = np.array([0, 1, 1, 0, 1, 0, 2, 1, 2, 1]) >>> multiclass_statistical_parity(p_attr, y_pred, aggregation_fun="max") 0.5