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