-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics.py
28 lines (21 loc) · 884 Bytes
/
metrics.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
def recall(confusion_matrix: dict): # noqa
return confusion_matrix["true_positive"] / (
confusion_matrix["true_positive"] + confusion_matrix["false_negative"]
)
def precision(confusion_matrix: dict): # noqa
return confusion_matrix["true_positive"] / (
confusion_matrix["true_positive"] + confusion_matrix["false_positive"]
)
def f1(confusion_matrix: dict): # noqa
return (
2
* (precision(confusion_matrix) * recall(confusion_matrix))
/ (precision(confusion_matrix) + recall(confusion_matrix))
)
def accuracy(confusion_matrix: dict): # noqa
return (confusion_matrix["true_positive"] + confusion_matrix["true_negative"]) / (
confusion_matrix["true_positive"]
+ confusion_matrix["true_negative"]
+ confusion_matrix["false_positive"]
+ confusion_matrix["false_negative"]
)