1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| import matplotlib.pyplot as plt import numpy as np import pandas as pd from pylab import *
plt.figure(figsize=(8.3,6)) label_font = {'family':'Arial','weight':'normal','size':22} legend_font = {'family':'Arial','weight':'normal','size':15} plt.rcParams['xtick.direction'] = 'in' plt.rcParams['ytick.direction'] = 'in' plt.yticks(fontproperties = 'Arial', size = 24) plt.xticks(fontproperties = 'Arial', size = 20) plt.ylabel('$\mathregular{R^{2}}$'+' coefficient of determination',label_font) plt.xlabel('Number of features',label_font) tick_params(which='major',width=2,length=6) ax=plt.gca() bwith = 2 ax.spines['bottom'].set_linewidth(bwith) ax.spines['top'].set_linewidth(bwith) ax.spines['left'].set_linewidth(bwith) ax.spines['right'].set_linewidth(bwith)
plt.ylim([0,1]) my_x_ticks = np.arange(1, 6, 1) plt.xticks(my_x_ticks) plt.title('Random forest regression',fontsize=20)
d = [1,2,3,4,5] r2_rf = [0.822,0.888,0.964,0.964,0.964] r2tr_rf = [0.8264,0.892,0.9629,0.964,0.9604] r2te_rf = [0.5456,0.5919,0.7318,0.7362,0.7203]
plt.plot(d,r2_rf,'o',ls='solid',lw=1,markeredgecolor='black',markersize=8,label='Entire dataset(50 cases) without cross-validation') plt.plot(d,r2tr_rf,'s',ls='solid',lw=1,markeredgecolor='black',markersize=8,label='Trainning dataset(45 cases)') plt.plot(d,r2te_rf,'^',ls='solid',lw=1,markeredgecolor='black',markersize=8,label='Test dataset(5 cases)')
plt.legend(loc='best',prop =legend_font,fancybox=False,edgecolor='black') plt.tight_layout() plt.savefig('rfr.pdf',dpi = 300) plt.show()
|