-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEvaluate.py
executable file
·56 lines (50 loc) · 1.62 KB
/
Evaluate.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
#coding=utf-8
def ComputeR10_1(scores,labels,count = 10):
total = 0
correct = 0
for i in range(len(labels)):
if labels[i] == 1:
total = total+1
sublist = scores[i:i+count]
if max(sublist) == scores[i]:#如果最大的就是第一个那就判断正确
correct = correct + 1
score=float(correct)/ total
print('R10_1',score )
def ComputeR2_1(scores,labels,count = 2):
total = 0
correct = 0
for i in range(len(labels)):
if labels[i] == 1:
total = total+1
sublist = scores[i:i+count]
if max(sublist) == scores[i]:
correct = correct + 1
score=float(correct) / total
print('R2_1',score )
def ComputeR10_2(scores,labels,hit=2,count = 10):
total = 0
correct = 0
for i in range(len(labels)):
if labels[i] == 1:
pos_score=scores[i]
total = total+1
sublist = scores[i:i+count]
curr = sorted(sublist, reverse=True) #from large to small
if curr[hit-1] <= pos_score:
correct = correct + 1
score=float(correct) / total
print('R10_2',score )
def ComputeR10_5(scores,labels,hit=5,count = 10):
total = 0
correct = 0
for i in range(len(labels)):
if labels[i] == 1:
pos_score=scores[i]
total = total+1
sublist = scores[i:i+count]
curr = sorted(sublist, reverse=True) #from large to small
if curr[hit-1] <= pos_score:
correct = correct + 1
score=float(correct) / total
print('R10_5',score )
return score