e@0: # -*- coding: utf-8 -*- e@0: """ e@0: Created on Mon Jul 13 06:45:38 2015 e@0: e@0: @author: Emmanouil Theofanis Chourdakis e@0: """ e@0: e@0: e@0: # Plots for our paper e@0: e@0: from numpy import * e@0: import matplotlib.pyplot as plt e@0: from matplotlib import rc e@0: #from matplotlib2tikz import save as tikz_save e@0: rc('font',**{'family':'serif','serif':['Palatino']}) e@0: rc('text', usetex=True) e@0: rc('pgf', texsystem='pdflatex') e@0: e@0: sucrats1 = (0.716, 0.793, 0.703, 0.696, 0.820) e@0: sucrats2 = (0.789, 0.789, 0.729, 0.525, 0.793) e@0: sucrats3 = (0.769, 0.736, 0.760, 0.537, 0.709) e@0: sucrats4 = (0.689, 0.689, 0.552, 0.562, 0.673) e@0: sucrats5 = (0.80508403361344549, 0.77222689075630258, 0.76915966386554613, 0.5345168067226892, 0.7770588235294118) e@0: sucrats6 = (0.796, 0.898, 0.798, 0.563, 0.875) e@0: e@0: 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: e@0: FONTSIZE=20 e@0: e@0: GNBCR = [] e@0: SVMR = [] e@0: HMMCR = [] e@0: HMMSVMR = [] e@0: SINKHOLE = [] e@0: e@0: e@0: e@0: e@0: labels = ['Set 1', 'Set 2', 'Set 3', 'Set 4', 'Set 5', 'Set 6'] e@0: e@0: results = [sucrats1, sucrats2, sucrats3, sucrats4] e@0: e@0: for i in range(0, len(results)): e@0: GNBCR.append(results[i][0]) e@0: SVMR.append(results[i][1]) e@0: HMMCR.append(results[i][2]) e@0: HMMSVMR.append(results[i][3]) e@0: SINKHOLE.append(results[i][4]) e@0: e@0: e@0: pos = list(range(len(SVMR))) e@0: width = 0.15 e@0: e@0: fig,ax=plt.subplots(figsize=(10,10)) e@0: e@0: bar1=plt.bar(pos, GNBCR, width, e@0: alpha=0.5, e@0: color='r', e@0: hatch='x', # this one defines the fill pattern e@0: label=labels[0]) e@0: e@0: plt.bar([p + width for p in pos], SVMR, width, e@0: alpha=0.5, e@0: color='g', e@0: hatch='-', e@0: label=labels[1]) e@0: e@0: plt.bar([p + width*2 for p in pos], HMMCR, width, e@0: alpha=0.5, e@0: color='b', e@0: hatch='', e@0: label=labels[2]) e@0: e@0: plt.bar([p + width*3 for p in pos], HMMSVMR, width, e@0: alpha=0.5, e@0: color='c',hatch='/', e@0: label=labels[3]) e@0: e@0: plt.bar([p + width*4 for p in pos], SINKHOLE, width, e@0: alpha=0.5, e@0: color='m',hatch='\\', e@0: label=labels[3]) e@0: e@0: e@0: e@0: # Setting axis labels and ticks e@0: ax.set_ylabel('Success Ratio', fontsize=FONTSIZE) e@0: ax.set_xlabel('Data set', fontsize=FONTSIZE) e@0: ax.set_title('Classifier Success Ratio', fontsize=FONTSIZE) e@0: ax.set_xticks([p + 2 * width for p in pos]) e@0: ax.set_yticks([0, 0.2, 0.6, 0.8, 1.0]) e@0: ax.set_xticklabels(labels, fontsize=FONTSIZE) e@0: ax.set_yticklabels([0, 0.2, 0.6, 0.8, 1.0], fontsize=FONTSIZE) e@0: e@0: # Setting the x-axis and y-axis limits e@0: plt.xlim(min(pos)-width, max(pos)+width*6) e@0: plt.ylim([0,1.2]) e@0: e@0: # Adding the legend and showing the plot e@0: leg = plt.legend(['GNB', 'SVM', 'HMM', 'HMM/SVM', 'SINK-HOLE'], loc='upper right', fontsize=FONTSIZE, fancybox=True) e@0: e@0: # leg.get_frame().set_alpha(0.5) e@0: plt.grid() e@0: #plt.show() e@0: e@0: #tikz_save('plot.tkz', figureheight='4cm', figurewidth='6cm') e@0: fig.tight_layout() e@0: fig.savefig('./plot.pgf', dpi=500) e@0: e@0: from sklearn import metrics e@0: def plot_confusion_matrix(y_pred, y): e@0: plt.imshow(metrics.confusion_matrix(y, y_pred), e@0: cmap=plt.cm.binary, interpolation='nearest') e@0: plt.colorbar() e@0: plt.xlabel('true value') e@0: plt.ylabel('predicted value') e@0: e@0: #plt.figure() e@0: #plot_confusion_matrix(predhmmc3, parameters_state) e@0: e@0: e@0: msecrats1 = (0.015, 0.013, 0.019, 0.012, 0.007) e@0: msecrats2 = (0.005, 0.006, 0.009, 0.007, 0.004) e@0: msecrats3 = (0.018, 0.020, 0.014, 0.019, 0.019) e@0: msecrats4 = (0.010, 0.010, 0.018, 0.010, 0.010) e@0: msecrats5 = (0.097, 0.014, 0.013, 0.017, 0.010) e@0: msecrats6 = (0.006, 0.003, 0.012, 0.013, 0.003) e@0: e@0: e@0: results = [msecrats1, msecrats2, msecrats3, msecrats4, msecrats5, msecrats6] e@0: e@0: GNBCR = [] e@0: SVMR = [] e@0: HMMCR = [] e@0: HMMSVMR = [] e@0: SINKHOLE = [] e@0: for i in range(0, len(results)): e@0: GNBCR.append(results[i][0]) e@0: SVMR.append(results[i][1]) e@0: HMMCR.append(results[i][2]) e@0: HMMSVMR.append(results[i][3]) e@0: SINKHOLE.append(results[i][4]) e@0: e@0: pos = list(range(len(SVMR))) e@0: e@0: plt.close('all') e@0: #plt.figure() e@0: fig,ax=plt.subplots(figsize=(10,10)) e@0: e@0: e@0: e@0: bar1=plt.barh(pos, GNBCR, width, e@0: alpha=0.5, e@0: color='r', e@0: hatch='x', # this one defines the fill pattern e@0: label=labels[0]) e@0: e@0: plt.barh([p + width for p in pos], SVMR, width, e@0: alpha=0.5, e@0: color='g', e@0: hatch='-', e@0: label=labels[1]) e@0: e@0: plt.barh([p + width*2 for p in pos], HMMCR, width, e@0: alpha=0.5, e@0: color='b', e@0: hatch='', e@0: label=labels[2]) e@0: e@0: plt.barh([p + width*3 for p in pos], HMMSVMR, width, e@0: alpha=0.5, e@0: color='c',hatch='/', e@0: label=labels[3]) e@0: e@0: plt.barh([p + width*4 for p in pos], SINKHOLE, width, e@0: alpha=0.5, e@0: color='m',hatch='\\', e@0: label=labels[3]) e@0: e@0: e@0: # Setting axis labels and ticks e@0: ax.set_ylabel('Data set', fontsize=FONTSIZE) e@0: ax.set_xlabel('Mean Squared Error', fontsize=FONTSIZE) e@0: ax.set_title('Mean Squared Errors', fontsize=FONTSIZE) e@0: ax.set_yticks([p + 2 * width for p in pos]) e@0: ax.set_xticks([0, 0.02]) e@0: ax.set_yticklabels(labels, fontsize=FONTSIZE) e@0: ax.set_xticklabels([0, 0.02], fontsize=FONTSIZE) e@0: e@0: # Setting the x-axis and y-axis limits e@0: plt.ylim(min(pos)-width, max(pos)+width*6) e@0: plt.xlim([0,0.03]) e@0: e@0: # Adding the legend and showing the plot e@0: leg = plt.legend(['GNB', 'SVM', 'HMM', 'HMM/SVM', 'SINK-HOLE'], loc='upper right', fontsize=FONTSIZE, fancybox=True) e@0: e@0: # leg.get_frame().set_alpha(0.5) e@0: plt.grid() e@0: e@0: e@0: #tikz_save('plot.tkz', figureheight='4cm', figurewidth='6cm') e@0: fig.tight_layout() e@0: fig.savefig('./plotmses.pgf', dpi=500) e@0: e@0: from sklearn import metrics e@0: def plot_confusion_matrix(y_pred, y): e@0: plt.imshow(metrics.confusion_matrix(y, y_pred), e@0: cmap=plt.cm.binary, interpolation='nearest') e@0: plt.colorbar() e@0: plt.xlabel('true value') e@0: plt.ylabel('predicted value') e@0: #plt.show()