-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics_hai.py
41 lines (35 loc) · 1.45 KB
/
metrics_hai.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import numpy as np
def get_metrics(preds, truths, metric_y):
# to be implemented for each method, higher better
'''
preds: array of predictions
truths: target array
'''
acc = metric_y(truths, preds) #metrics.accuracy_score(truths, preds)
metrics_computed = { "score": acc}
return metrics_computed
def compute_metrics(human_preds, ai_preds, reject_decisions, truths, metric_y, to_print = False):
coverage = 1 - np.sum(reject_decisions)/len(reject_decisions)
humanai_preds = []
human_preds_sys = []
truths_human = []
ai_preds_sys = []
truths_ai = []
for i in range(len(reject_decisions)):
if reject_decisions[i] == 1:
humanai_preds.append(ai_preds[i])
ai_preds_sys.append(ai_preds[i])
truths_ai.append(truths[i])
else:
humanai_preds.append(human_preds[i])
human_preds_sys.append(human_preds[i])
truths_human.append(truths[i])
humanai_metrics = get_metrics(humanai_preds, truths, metric_y)
human_metrics = get_metrics(human_preds_sys, truths_human, metric_y)
ai_metrics = get_metrics(ai_preds_sys, truths_ai, metric_y)
if to_print:
print(f'Coverage is {coverage*100:.2f}')
print(f' metrics of system are: {humanai_metrics}')
print(f' metrics of human are: {human_metrics}')
print(f' metrics of AI are: {ai_metrics}')
return coverage, humanai_metrics, human_metrics, ai_metrics