-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEvaluation_CMC.py
83 lines (67 loc) · 2.42 KB
/
Evaluation_CMC.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import pandas as pd
from matplotlib import pyplot as plt
def return_first_one_prob(prob):
for index in range(len(prob)):
if prob[index] == 1.0:
return index
def evaluate(dataset):
x = pd.read_csv(dataset)
real = x.REAL
scores = x.SCORES
for i in range(len(scores)):
scores[i] = scores[i][1:-1]
scores[i] = scores[i].split()
for j in range(len(scores[i])):
scores[i][j] = float(scores[i][j])
for i in range(len(scores)):
for j in range(len(scores[0])):
scores[i][j] = (scores[i][j], j)
# RANK
ranks = len(scores[0])
CMS = dict()
c = 0
for k in range(ranks):
CMS[k + 1] = c
for i in range(len(real)):
s_scores = sorted(scores[i], reverse=True)
if s_scores[k][1] == real[i]:
CMS[k + 1] += 1
c += 1
CMS[k + 1] = CMS[k + 1] / len(real)
prob = [0] + (list(CMS.values()))
index_first_prob_one = return_first_one_prob(prob)
plt.figure()
plt.plot(list(range(ranks + 1)), prob)
plt.plot(index_first_prob_one, prob[index_first_prob_one], "x",
label="Probability = 1.0 at rank " + str(index_first_prob_one))
plt.axvline(index_first_prob_one, color='r', linestyle=":", linewidth='1')
# plt.xlim([0.0, 5.0])
plt.ylim([0.0, 1.05])
plt.xlabel('Ranks')
plt.ylabel('Prob. of identification')
plt.title('Cumulative Match Characteristic')
plt.grid()
plt.legend(loc="lower right")
plt.savefig('plot/CMC/CMC.svg', dpi=1200)
plt.clf()
plt.figure()
plt.plot(list(range(1, 6)), prob[1:6])
plt.plot(list(range(1, 6)), prob[1:6], 'x')
plt.ylim([0.8530, 0.88])
plt.xlim([0.8, 5.5])
plt.xlabel('Ranks')
plt.ylabel('Prob. of identification')
plt.title('Cumulative Match Characteristic')
plt.grid()
plt.legend(loc="lower right")
for label, xi, yi in zip(prob[1:6], list(range(1, 6)), prob[1:6]):
plt.annotate("{:.3f}".format(label), xy=(xi, yi), xytext=(0, -12), textcoords='offset points')
plt.savefig('plot/CMC/CMC_at_rank_5.svg', dpi=1200)
plt.clf()
print("Score at rank 1 (Also Called Recognition Rate): ", CMS[1])
print("Score at rank 2: ", CMS[2])
print("Score at rank 3: ", CMS[3])
print("Score at rank 3: ", CMS[4])
print("Score at rank 5: ", CMS[5])
if __name__ == '__main__':
evaluate("datasets/predictions_dataset.csv")