Mercurial > hg > chourdakisreiss2016
comparison experiment-reverb/code/plots.py @ 0:246d5546657c
initial commit, needs cleanup
author | Emmanouil Theofanis Chourdakis <e.t.chourdakis@qmul.ac.uk> |
---|---|
date | Wed, 14 Dec 2016 13:15:48 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:246d5546657c |
---|---|
1 # -*- coding: utf-8 -*- | |
2 """ | |
3 Created on Mon Jul 13 06:45:38 2015 | |
4 | |
5 @author: Emmanouil Theofanis Chourdakis | |
6 """ | |
7 | |
8 | |
9 # Plots for our paper | |
10 | |
11 from numpy import * | |
12 import matplotlib.pyplot as plt | |
13 from matplotlib import rc | |
14 #from matplotlib2tikz import save as tikz_save | |
15 rc('font',**{'family':'serif','serif':['Palatino']}) | |
16 rc('text', usetex=True) | |
17 rc('pgf', texsystem='pdflatex') | |
18 | |
19 sucrats1 = (0.716, 0.793, 0.703, 0.696, 0.820) | |
20 sucrats2 = (0.789, 0.789, 0.729, 0.525, 0.793) | |
21 sucrats3 = (0.769, 0.736, 0.760, 0.537, 0.709) | |
22 sucrats4 = (0.689, 0.689, 0.552, 0.562, 0.673) | |
23 sucrats5 = (0.80508403361344549, 0.77222689075630258, 0.76915966386554613, 0.5345168067226892, 0.7770588235294118) | |
24 sucrats6 = (0.796, 0.898, 0.798, 0.563, 0.875) | |
25 | |
26 example = {'SIM/C1':(0.5,0.7,0.6,0.8), 'FUL/C1':(0.6,0.7,0.9,0.8), 'SIM/C2': (0.4,0.3,0.5,0.6)} | |
27 | |
28 FONTSIZE=20 | |
29 | |
30 GNBCR = [] | |
31 SVMR = [] | |
32 HMMCR = [] | |
33 HMMSVMR = [] | |
34 SINKHOLE = [] | |
35 | |
36 | |
37 | |
38 | |
39 labels = ['Set 1', 'Set 2', 'Set 3', 'Set 4', 'Set 5', 'Set 6'] | |
40 | |
41 results = [sucrats1, sucrats2, sucrats3, sucrats4] | |
42 | |
43 for i in range(0, len(results)): | |
44 GNBCR.append(results[i][0]) | |
45 SVMR.append(results[i][1]) | |
46 HMMCR.append(results[i][2]) | |
47 HMMSVMR.append(results[i][3]) | |
48 SINKHOLE.append(results[i][4]) | |
49 | |
50 | |
51 pos = list(range(len(SVMR))) | |
52 width = 0.15 | |
53 | |
54 fig,ax=plt.subplots(figsize=(10,10)) | |
55 | |
56 bar1=plt.bar(pos, GNBCR, width, | |
57 alpha=0.5, | |
58 color='r', | |
59 hatch='x', # this one defines the fill pattern | |
60 label=labels[0]) | |
61 | |
62 plt.bar([p + width for p in pos], SVMR, width, | |
63 alpha=0.5, | |
64 color='g', | |
65 hatch='-', | |
66 label=labels[1]) | |
67 | |
68 plt.bar([p + width*2 for p in pos], HMMCR, width, | |
69 alpha=0.5, | |
70 color='b', | |
71 hatch='', | |
72 label=labels[2]) | |
73 | |
74 plt.bar([p + width*3 for p in pos], HMMSVMR, width, | |
75 alpha=0.5, | |
76 color='c',hatch='/', | |
77 label=labels[3]) | |
78 | |
79 plt.bar([p + width*4 for p in pos], SINKHOLE, width, | |
80 alpha=0.5, | |
81 color='m',hatch='\\', | |
82 label=labels[3]) | |
83 | |
84 | |
85 | |
86 # Setting axis labels and ticks | |
87 ax.set_ylabel('Success Ratio', fontsize=FONTSIZE) | |
88 ax.set_xlabel('Data set', fontsize=FONTSIZE) | |
89 ax.set_title('Classifier Success Ratio', fontsize=FONTSIZE) | |
90 ax.set_xticks([p + 2 * width for p in pos]) | |
91 ax.set_yticks([0, 0.2, 0.6, 0.8, 1.0]) | |
92 ax.set_xticklabels(labels, fontsize=FONTSIZE) | |
93 ax.set_yticklabels([0, 0.2, 0.6, 0.8, 1.0], fontsize=FONTSIZE) | |
94 | |
95 # Setting the x-axis and y-axis limits | |
96 plt.xlim(min(pos)-width, max(pos)+width*6) | |
97 plt.ylim([0,1.2]) | |
98 | |
99 # Adding the legend and showing the plot | |
100 leg = plt.legend(['GNB', 'SVM', 'HMM', 'HMM/SVM', 'SINK-HOLE'], loc='upper right', fontsize=FONTSIZE, fancybox=True) | |
101 | |
102 # leg.get_frame().set_alpha(0.5) | |
103 plt.grid() | |
104 #plt.show() | |
105 | |
106 #tikz_save('plot.tkz', figureheight='4cm', figurewidth='6cm') | |
107 fig.tight_layout() | |
108 fig.savefig('./plot.pgf', dpi=500) | |
109 | |
110 from sklearn import metrics | |
111 def plot_confusion_matrix(y_pred, y): | |
112 plt.imshow(metrics.confusion_matrix(y, y_pred), | |
113 cmap=plt.cm.binary, interpolation='nearest') | |
114 plt.colorbar() | |
115 plt.xlabel('true value') | |
116 plt.ylabel('predicted value') | |
117 | |
118 #plt.figure() | |
119 #plot_confusion_matrix(predhmmc3, parameters_state) | |
120 | |
121 | |
122 msecrats1 = (0.015, 0.013, 0.019, 0.012, 0.007) | |
123 msecrats2 = (0.005, 0.006, 0.009, 0.007, 0.004) | |
124 msecrats3 = (0.018, 0.020, 0.014, 0.019, 0.019) | |
125 msecrats4 = (0.010, 0.010, 0.018, 0.010, 0.010) | |
126 msecrats5 = (0.097, 0.014, 0.013, 0.017, 0.010) | |
127 msecrats6 = (0.006, 0.003, 0.012, 0.013, 0.003) | |
128 | |
129 | |
130 results = [msecrats1, msecrats2, msecrats3, msecrats4, msecrats5, msecrats6] | |
131 | |
132 GNBCR = [] | |
133 SVMR = [] | |
134 HMMCR = [] | |
135 HMMSVMR = [] | |
136 SINKHOLE = [] | |
137 for i in range(0, len(results)): | |
138 GNBCR.append(results[i][0]) | |
139 SVMR.append(results[i][1]) | |
140 HMMCR.append(results[i][2]) | |
141 HMMSVMR.append(results[i][3]) | |
142 SINKHOLE.append(results[i][4]) | |
143 | |
144 pos = list(range(len(SVMR))) | |
145 | |
146 plt.close('all') | |
147 #plt.figure() | |
148 fig,ax=plt.subplots(figsize=(10,10)) | |
149 | |
150 | |
151 | |
152 bar1=plt.barh(pos, GNBCR, width, | |
153 alpha=0.5, | |
154 color='r', | |
155 hatch='x', # this one defines the fill pattern | |
156 label=labels[0]) | |
157 | |
158 plt.barh([p + width for p in pos], SVMR, width, | |
159 alpha=0.5, | |
160 color='g', | |
161 hatch='-', | |
162 label=labels[1]) | |
163 | |
164 plt.barh([p + width*2 for p in pos], HMMCR, width, | |
165 alpha=0.5, | |
166 color='b', | |
167 hatch='', | |
168 label=labels[2]) | |
169 | |
170 plt.barh([p + width*3 for p in pos], HMMSVMR, width, | |
171 alpha=0.5, | |
172 color='c',hatch='/', | |
173 label=labels[3]) | |
174 | |
175 plt.barh([p + width*4 for p in pos], SINKHOLE, width, | |
176 alpha=0.5, | |
177 color='m',hatch='\\', | |
178 label=labels[3]) | |
179 | |
180 | |
181 # Setting axis labels and ticks | |
182 ax.set_ylabel('Data set', fontsize=FONTSIZE) | |
183 ax.set_xlabel('Mean Squared Error', fontsize=FONTSIZE) | |
184 ax.set_title('Mean Squared Errors', fontsize=FONTSIZE) | |
185 ax.set_yticks([p + 2 * width for p in pos]) | |
186 ax.set_xticks([0, 0.02]) | |
187 ax.set_yticklabels(labels, fontsize=FONTSIZE) | |
188 ax.set_xticklabels([0, 0.02], fontsize=FONTSIZE) | |
189 | |
190 # Setting the x-axis and y-axis limits | |
191 plt.ylim(min(pos)-width, max(pos)+width*6) | |
192 plt.xlim([0,0.03]) | |
193 | |
194 # Adding the legend and showing the plot | |
195 leg = plt.legend(['GNB', 'SVM', 'HMM', 'HMM/SVM', 'SINK-HOLE'], loc='upper right', fontsize=FONTSIZE, fancybox=True) | |
196 | |
197 # leg.get_frame().set_alpha(0.5) | |
198 plt.grid() | |
199 | |
200 | |
201 #tikz_save('plot.tkz', figureheight='4cm', figurewidth='6cm') | |
202 fig.tight_layout() | |
203 fig.savefig('./plotmses.pgf', dpi=500) | |
204 | |
205 from sklearn import metrics | |
206 def plot_confusion_matrix(y_pred, y): | |
207 plt.imshow(metrics.confusion_matrix(y, y_pred), | |
208 cmap=plt.cm.binary, interpolation='nearest') | |
209 plt.colorbar() | |
210 plt.xlabel('true value') | |
211 plt.ylabel('predicted value') | |
212 #plt.show() |