Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pylab import plot, show, savefig, xlim, figure, hold, ylim, legend, boxplot, setp, axes
- ### Takes output of KFold_within_loo()[1], returns selected features and their frequencies of being selected
- def sel_features2(M):
- feat=[]
- for item in M:
- for i in item:
- feat.append(i)
- sfeat=sorted(feat)
- sel_feat_freq=scipy.stats.itemfreq(sfeat)
- return sel_feat_freq
- def setBoxColors(bp):
- setp(bp['boxes'][0], color='blue')
- setp(bp['caps'][0], color='blue')
- setp(bp['caps'][1], color='blue')
- setp(bp['whiskers'][0], color='blue')
- setp(bp['whiskers'][1], color='blue')
- setp(bp['fliers'][0], color='blue')
- setp(bp['medians'][0], color='blue')
- setp(bp['boxes'][1], color='red')
- setp(bp['caps'][2], color='red')
- setp(bp['caps'][3], color='red')
- setp(bp['whiskers'][2], color='red')
- setp(bp['whiskers'][3], color='red')
- setp(bp['fliers'][1], color='red')
- setp(bp['medians'][1], color='red')
- def plot_multiple_boxplots(features, target, standardize=False, sel_features2_output=None, threshold=0, fig_size=(10,6)):
- TD_ind_find=np.where(np.array(target)==0)[0]
- ASD_ind_find=np.where(np.array(target)==1)[0]
- if standardize==False:
- features_ready=features
- else:
- features_ready=(features - np.mean(features, 0))/np.std(features, 0)
- if sel_features2_output!=None:
- subset_indexes=sel_features2_output[np.where(sel_features2_output[:,1]>=threshold),0]
- set_to_plot=features_ready[:, subset_indexes[0]]
- else:
- set_to_plot=features_ready
- fig = figure(figsize=fig_size)
- ax = axes()
- hold(True)
- for j in range(0, set_to_plot.shape[1]):
- feature_to_plot=[set_to_plot[TD_ind_find, j], set_to_plot[ASD_ind_find, j]]
- bp = boxplot(feature_to_plot, positions = [1+j*3, 2+j*3], widths = 0.6)
- setBoxColors(bp)
- # set axes limits and labels
- xlim(0, 3*set_to_plot.shape[1]+1)
- ylim(np.min(set_to_plot), np.max(set_to_plot))
- tick_positions=[]
- for i in range(0, set_to_plot.shape[1]):
- tick_positions.append(1.5 + 3*i)
- ax.set_xticks(tick_positions)
- ax.set_xticklabels(range(1, set_to_plot.shape[1]+1))
- # draw temporary red and blue lines and use them to create a legend
- hASD, = plot([1,1],'b-')
- hTD, = plot([1,1],'r-')
- legend((hASD, hTD),('TD', 'ASD'))
- hASD.set_visible(False)
- hTD.set_visible(False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement