File size: 1,104 Bytes
8d7d29c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163dff6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import evaluate as ev
from nDCG import nDCG

metric = nDCG(cache_dir="cache")
a = [1,2,3,4,5]
b = [1,2,3,4,5]
c = [1,2,3,4,0]


#metric.add(prediction=a, reference=b)
metric.add(prediction=c, reference=b)
metric.add(prediction=c, reference=b)
metric.add(prediction=c, reference=b)
print(metric.compute(predictions=[a], references=[b]))
print(metric.compute(predictions=[a], references=[c]))
print(metric.compute(predictions=[a], references=[c]))
print(metric.compute(predictions=[a,a], references=[c,a]))
print(metric.cache_file_name)

nDCG_metric = ev.load("nDCG.py")
results = nDCG_metric.compute(references=[[10, 0, 0, 1, 5]], predictions=[[.1, .2, .3, 4, 70]])
print(results)

nDCG_metric = ev.load("nDCG.py")
results = nDCG_metric.compute(references=[[10, 0, 0, 1, 5]], predictions=[[.1, .2, .3, 4, 70]], k=3)
print(results)

nDCG_metric = ev.load("nDCG.py")
results = nDCG_metric.compute(references=[[1, 0, 0, 0, 0]], predictions=[[1, 1, 0, 0, 0]], k=1)
print(results)

results = nDCG_metric.compute(references=[[1, 0, 0, 0, 0]], predictions=[[1, 1, 0, 0, 0]], k=1, ignore_ties=True)
print(results)