-
Notifications
You must be signed in to change notification settings - Fork 842
/
common_utils.py
26 lines (23 loc) · 1.31 KB
/
common_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Metrics function
from collections import OrderedDict
from aif360.metrics import ClassificationMetric
def compute_metrics(dataset_true, dataset_pred,
unprivileged_groups, privileged_groups,
disp = True):
""" Compute the key metrics """
classified_metric_pred = ClassificationMetric(dataset_true,
dataset_pred,
unprivileged_groups=unprivileged_groups,
privileged_groups=privileged_groups)
metrics = OrderedDict()
metrics["Balanced accuracy"] = 0.5*(classified_metric_pred.true_positive_rate()+
classified_metric_pred.true_negative_rate())
metrics["Statistical parity difference"] = classified_metric_pred.statistical_parity_difference()
metrics["Disparate impact"] = classified_metric_pred.disparate_impact()
metrics["Average odds difference"] = classified_metric_pred.average_odds_difference()
metrics["Equal opportunity difference"] = classified_metric_pred.equal_opportunity_difference()
metrics["Theil index"] = classified_metric_pred.theil_index()
if disp:
for k in metrics:
print("%s = %.4f" % (k, metrics[k]))
return metrics