Metrics
There are various metrics measuring the goodness-of-fit. Common metrics include F1 Score, Recall, Precision, etc. See a table from Wikipedia for some of these metrics and their definitions. GenoLearn has implemented most of these metrics as shown below.
1def recall(TP, TN, FP, FN):
2 return TP / (TP + FN)
3
4def specificity(TP, TN, FP, FN):
5 return TN / (TN + FP)
6
7def precision(TP, TN, FP, FN):
8 return TP / (TP + FP)
9
10def negative_predictive_value(TP, TN, FP, FN):
11 return TN / (TN + FN)
12
13def false_negative_rate(TP, TN, FP, FN):
14 return FN / (FN + TP)
15
16def false_positive_rate(TP, TN, FP, FN):
17 return FP / (FP + TN)
18
19def false_discovery_rate(TP, TN, FP, FN):
20 return FP / (FP + TP)
21
22def false_omission_rate(TP, TN, FP, FN):
23 return FN / (FN + TN)
24
25def positive_likelihood_ratio(TP, TN, FP, FN):
26 return recall(TP, TN, FP, FN) / false_positive_rate(TP, TN, FP, FN)
27
28def negative_likelihood_ratio(TP, TN, FP, FN):
29 return false_negative_rate(TP, TN, FP, FN) / specificity(TP, TN, FP, FN)
30
31def prevalence_threshold(TP, TN, FP, FN):
32 fpr = false_positive_rate(TP, TN, FP, FN)
33 tpr = recall(TP, TN, FP, FN)
34 return (fpr ** .5) / ((fpr ** .5) + (tpr ** .5))
35
36def threat_score(TP, TN, FP, FN):
37 return TP / (TP + FN + FP)
38
39def prevalence(TP, TN, FP, FN):
40 return (TP + FN) / (TP + TN + FP + FN)
41
42def accuracy(TP, TN, FP, FN):
43 return (TP + TN) / (TP + TN + FP + FN)
44
45def balanced_accuracy(TP, TN, FP, FN):
46 return (recall(TP, TN, FP, FN) + specificity(TP, TN, FP, FN)) / 2
47
48def f1_score(TP, TN, FP, FN):
49 return 2 * TP / (2 * TP + FP + FN)
50
51def phi_coefficient(TP, TN, FP, FN):
52 return (TP * TN + FP * FN) / (((TP + FP) * (TP + FN) * (TN + FP) * (TN + FN)) ** .5)
53
54def fowlkes_mallows_index(TP, TN, FP, FN):
55 return (false_discovery_rate(TP, TN, FP, FN) * recall(TP, TN, FP, FN)) ** .5
56
57def informedness(TP, TN, FP, FN):
58 return recall(TP, TN, FP, FN) + specificity(TP, TN, FP, FN) - 1
59
60def markedness(TP, TN, FP, FN):
61 return precision(TP, TN, FP, FN) + negative_predictive_value(TP, TN, FP, FN) - 1
62
63def diagnostics_odds_ratio(TP, TN, FP, FN):
64 return positive_likelihood_ratio(TP, TN, FP, FN) / negative_likelihood_ratio(TP, TN, FP, FN)