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