-
Notifications
You must be signed in to change notification settings - Fork 4
/
evaluationmatrix.py
67 lines (50 loc) · 1.64 KB
/
evaluationmatrix.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import numpy as np
def fpr(matrix,n_exp):
diag = []
preMatrix = []
reMatrix = []
preList = []
reList = []
denominator_De_zero = 0.00001
for index in range(n_exp):
diag = matrix[index,index]
col = sum(matrix[:,index])
row = sum(matrix[index])
# print(diag)
# print(col)
if index == 0:
prec = diag/(col + denominator_De_zero)
# print(prec)
rec = diag/(row + denominator_De_zero)
# print(rec)
else:
prec = prec + diag/(col + denominator_De_zero)
# print(prec)
rec = rec + diag/(row + denominator_De_zero)
# print(rec)
precision = prec / (n_exp)
recall = rec /(n_exp
) # print(precision)
# print(recall)
f1 = 2 * precision * recall / (precision + recall)
return [f1,precision,recall]
def weighted_average_recall(matrix, n_exp, total_N):
# normal recognition accuracy
# war = no. correct classified samples / total number of samples
number_correct_classified = 0
for index in range(n_exp):
diag = matrix[index, index]
number_correct_classified += diag
war = number_correct_classified / total_N
return war
def unweighted_average_recall(matrix, n_exp):
# balanced recognition accuracy
# uar = sum(accuracy of each class ) / number of classes
sum_of_accuracy = 0
for index in range(n_exp):
diag = matrix[index, index]
row = sum(matrix[index])
accuracy_of_n_class = diag / row
sum_of_accuracy += accuracy_of_n_class
uar = sum_of_accuracy / n_exp
return uar