50220
|
1 |
#!/usr/bin/python
|
|
2 |
'''
|
|
3 |
Created on Jul 13, 2012
|
|
4 |
|
|
5 |
@author: Daniel Kuehlwein
|
|
6 |
'''
|
|
7 |
|
|
8 |
import sys
|
|
9 |
from argparse import ArgumentParser,RawDescriptionHelpFormatter
|
|
10 |
from matplotlib.pyplot import plot,figure,show,legend,xlabel,ylabel,axis,hist
|
|
11 |
from stats import Statistics
|
|
12 |
|
|
13 |
parser = ArgumentParser(description='Compare Statistics. \n\n\
|
|
14 |
Loads different statistics and displays a comparison. Requires the matplotlib module.\n\n\
|
|
15 |
-------- Example Usage ---------------\n\
|
|
16 |
./compareStats.py --statFiles ../tmp/natISANB.stats ../tmp/natATPNB.stats -b 30\n\n\
|
|
17 |
Author: Daniel Kuehlwein, July 2012',formatter_class=RawDescriptionHelpFormatter)
|
|
18 |
parser.add_argument('--statFiles', default=None, nargs='+',
|
|
19 |
help='The names of the saved statistic files.')
|
|
20 |
parser.add_argument('-b','--bins',default=50,help="Number of bins for the AUC histogram. Default=50.",type=int)
|
|
21 |
|
|
22 |
def main(argv = sys.argv[1:]):
|
|
23 |
args = parser.parse_args(argv)
|
|
24 |
if args.statFiles == None:
|
|
25 |
print 'Filenames missing.'
|
|
26 |
sys.exit(-1)
|
|
27 |
|
|
28 |
aucData = []
|
|
29 |
aucLabels = []
|
|
30 |
for statFile in args.statFiles:
|
|
31 |
s = Statistics()
|
|
32 |
s.load(statFile)
|
|
33 |
avgRecall = [float(x)/s.problems for x in s.recallData]
|
|
34 |
figure('Recall')
|
|
35 |
plot(range(s.cutOff),avgRecall,label=statFile)
|
|
36 |
legend(loc='lower right')
|
|
37 |
ylabel('Average Recall')
|
|
38 |
xlabel('Highest ranked premises')
|
|
39 |
axis([0,s.cutOff,0.0,1.0])
|
|
40 |
figure('100%Recall')
|
|
41 |
plot(range(s.cutOff),s.recall100Data,label=statFile)
|
|
42 |
legend(loc='lower right')
|
|
43 |
ylabel('100%Recall')
|
|
44 |
xlabel('Highest ranked premises')
|
|
45 |
axis([0,s.cutOff,0,s.problems])
|
|
46 |
aucData.append(s.aucData)
|
|
47 |
aucLabels.append(statFile)
|
|
48 |
figure('AUC Histogram')
|
|
49 |
hist(aucData,bins=args.bins,label=aucLabels,histtype='bar')
|
|
50 |
legend(loc='upper left')
|
|
51 |
ylabel('Problems')
|
|
52 |
xlabel('AUC')
|
|
53 |
|
|
54 |
show()
|
|
55 |
|
|
56 |
if __name__ == '__main__':
|
|
57 |
#args = ['--statFiles','../tmp/natISANB.stats','../tmp/natATPNB.stats','-b','30']
|
|
58 |
#sys.exit(main(args))
|
|
59 |
sys.exit(main())
|
|
60 |
|