Advertisement
Guest User

Untitled

a guest
May 24th, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. from pylab import plot, show, savefig, xlim, figure, hold, ylim, legend, boxplot, setp, axes
  2.  
  3. ### Takes output of KFold_within_loo()[1], returns selected features and their frequencies of being selected
  4. def sel_features2(M):
  5. feat=[]
  6. for item in M:
  7. for i in item:
  8. feat.append(i)
  9. sfeat=sorted(feat)
  10. sel_feat_freq=scipy.stats.itemfreq(sfeat)
  11. return sel_feat_freq
  12.  
  13. def setBoxColors(bp):
  14. setp(bp['boxes'][0], color='blue')
  15. setp(bp['caps'][0], color='blue')
  16. setp(bp['caps'][1], color='blue')
  17. setp(bp['whiskers'][0], color='blue')
  18. setp(bp['whiskers'][1], color='blue')
  19. setp(bp['fliers'][0], color='blue')
  20. setp(bp['medians'][0], color='blue')
  21.  
  22. setp(bp['boxes'][1], color='red')
  23. setp(bp['caps'][2], color='red')
  24. setp(bp['caps'][3], color='red')
  25. setp(bp['whiskers'][2], color='red')
  26. setp(bp['whiskers'][3], color='red')
  27. setp(bp['fliers'][1], color='red')
  28. setp(bp['medians'][1], color='red')
  29.  
  30.  
  31. def plot_multiple_boxplots(features, target, standardize=False, sel_features2_output=None, threshold=0, fig_size=(10,6)):
  32. TD_ind_find=np.where(np.array(target)==0)[0]
  33. ASD_ind_find=np.where(np.array(target)==1)[0]
  34.  
  35. if standardize==False:
  36. features_ready=features
  37. else:
  38. features_ready=(features - np.mean(features, 0))/np.std(features, 0)
  39.  
  40. if sel_features2_output!=None:
  41. subset_indexes=sel_features2_output[np.where(sel_features2_output[:,1]>=threshold),0]
  42. set_to_plot=features_ready[:, subset_indexes[0]]
  43.  
  44. else:
  45. set_to_plot=features_ready
  46.  
  47.  
  48. fig = figure(figsize=fig_size)
  49. ax = axes()
  50. hold(True)
  51.  
  52. for j in range(0, set_to_plot.shape[1]):
  53. feature_to_plot=[set_to_plot[TD_ind_find, j], set_to_plot[ASD_ind_find, j]]
  54. bp = boxplot(feature_to_plot, positions = [1+j*3, 2+j*3], widths = 0.6)
  55. setBoxColors(bp)
  56.  
  57. # set axes limits and labels
  58. xlim(0, 3*set_to_plot.shape[1]+1)
  59. ylim(np.min(set_to_plot), np.max(set_to_plot))
  60. tick_positions=[]
  61. for i in range(0, set_to_plot.shape[1]):
  62. tick_positions.append(1.5 + 3*i)
  63. ax.set_xticks(tick_positions)
  64.  
  65. ax.set_xticklabels(range(1, set_to_plot.shape[1]+1))
  66.  
  67. # draw temporary red and blue lines and use them to create a legend
  68. hASD, = plot([1,1],'b-')
  69. hTD, = plot([1,1],'r-')
  70. legend((hASD, hTD),('TD', 'ASD'))
  71. hASD.set_visible(False)
  72. hTD.set_visible(False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement