-
Notifications
You must be signed in to change notification settings - Fork 35
/
plot_ndcgs.py
37 lines (24 loc) · 885 Bytes
/
plot_ndcgs.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
"plot average NDCGs"
import cPickle as pickle
from collections import OrderedDict
from matplotlib import pyplot as plt
from os import listdir
from os.path import isfile, join
# minimum number of users we have scores for to average
min_users = 10
input_dir = 'ndcgs/'
# a list of input files
input_files = [ join( input_dir, f ) for f in listdir( input_dir ) if isfile( join( input_dir, f )) and f.endswith( '.pkl' ) ]
for i_f in input_files:
print i_f
#
ndcgs = [ pickle.load( open( i_f, 'rb' ))['ndcgs'] for i_f in input_files ]
for i in range( len( ndcgs )):
assert( sorted( ndcgs[i].keys()) == ndcgs[i].keys())
mean_ndcgs = [
OrderedDict( { k: sum( v ) / len( v ) for k, v in x.items() if len( v ) >= min_users } )
for x in ndcgs ]
colors = [ 'g', 'b', 'r', 'k', 'y' ]
for i, n in enumerate( mean_ndcgs ):
plt.plot( n.keys(), n.values(), colors[i] )
plt.show()