feature_importance.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. import matplotlib.pyplot as plt
  2. from sklearn.datasets import make_classification
  3. from sklearn.model_selection import train_test_split
  4. from sklearn.ensemble import RandomForestClassifier
  5. from sklearn.inspection import permutation_importance
  6. from sklearn.preprocessing import StandardScaler
  7. from sklearn.metrics import accuracy_score
  8. import numpy as np
  9. import pandas as pd
  10. from master_funcs import *
  11. from collections import Counter
  12. from imblearn.over_sampling import SMOTE
  13. from imblearn.under_sampling import RandomUnderSampler
  14. from imblearn.pipeline import Pipeline
  15. from imblearn.over_sampling import SMOTE
  16. import dill
  17. import warnings
  18. warnings.filterwarnings("ignore")
  19. %matplotlib qt
  20. patients=['PB_T2_3_1', 'PB_T2_3_2', 'PB_T2_3_3', 'PB_T2_4_2', 'PB_T2_5_1', 'PB_T2_6_1', 'PB_T2_6_2', 'PB_T3_23_1', 'PB_T3_23_2', 'PB_T3_23_3', 'PB_T3_24_1', 'PB_T3_24_2', 'PB_T3_24_3']
  21. for z in patients:
  22. dill.load_session('/home/user/Documents/Master/GW_'+z+'_data.pkl')
  23. names=df_vel_acc.columns.tolist()
  24. names=[sub.replace('acceleration', 'acc') for sub in names]
  25. names=[sub.replace('velocity', 'vel') for sub in names]
  26. names=[sub.replace('angle', 'ang') for sub in names]
  27. names=[sub.replace('right', 'r') for sub in names]
  28. names=[sub.replace('left', 'l') for sub in names]
  29. names=[sub.replace('top', 't') for sub in names]
  30. names=[sub.replace('bottom', 'b') for sub in names]
  31. importances = best_model.feature_importances_
  32. std = np.std([tree.feature_importances_ for tree in best_model.estimators_], axis=0)
  33. ranked=np.argsort(importances)[::-1]
  34. std=pd.Series(std)
  35. std=std.reindex(ranked)
  36. forest_importances = pd.Series(importances, index=names)
  37. forest_importances=forest_importances.sort_values(ascending=False)
  38. forest_importances=forest_importances[:20]
  39. fig, ax= plt.subplots()
  40. ax.figure.set_size_inches(5, 8)
  41. forest_importances.plot.bar(yerr=np.array(std[:20]/10), ax=ax)
  42. ax.set_ylabel('Mean decrease in impurity')
  43. plt.tight_layout()
  44. #plt.savefig('/home/user/owncloud/thesis_figures/GW_FI_'+z+'_3d.png', dpi=200)
  45. plt.show()
  46. forest_importances = pd.Series(result.importances_mean, index=names)
  47. forest_importances=forest_importances.sort_values(ascending=False)
  48. forest_importances=forest_importances[:20]
  49. fig, ax = plt.subplots()
  50. ax.figure.set_size_inches(5, 8)
  51. forest_importances.plot.bar(yerr=result.importances_std[:20], ax=ax)
  52. ax.set_ylabel('Mean accuracy decrease')
  53. fig.tight_layout()
  54. #fig.savefig('/home/user/owncloud/thesis_figures/GW_FI_PM_'+z+'_3d.png', dpi=200)
  55. plt.show()
  56. patients=['PB_T2_3_1', 'PB_T2_3_2', 'PB_T2_3_3', 'PB_T2_4_2', 'PB_T2_5_1', 'PB_T2_6_1', 'PB_T2_6_2', 'PB_T3_23_1', 'PB_T3_23_2', 'PB_T3_23_3', 'PB_T3_24_1', 'PB_T3_24_2', 'PB_T3_24_3']
  57. for z in patients:
  58. dill.load_session('/home/user/Documents/Master/GW_'+z+'_data.pkl')
  59. importances = best_model.feature_importances_
  60. names=df_vel_acc.columns.tolist()
  61. names=[sub.replace('acceleration', 'acc') for sub in names]
  62. names=[sub.replace('velocity', 'vel') for sub in names]
  63. names=[sub.replace('angle', 'ang') for sub in names]
  64. names=[sub.replace('right', 'r') for sub in names]
  65. names=[sub.replace('left', 'l') for sub in names]
  66. names=[sub.replace('top', 't') for sub in names]
  67. names=[sub.replace('bottom', 'b') for sub in names]
  68. if z=='PB_T2_3_1':
  69. total_imp=pd.Series(np.zeros((df_vel_acc.shape[1])), index=names)
  70. total_imp_perm=pd.Series(np.zeros((df_vel_acc.shape[1])), index=names)
  71. forest_importances = pd.Series(importances, index=names)
  72. total_imp+=forest_importances*acc_score
  73. forest_importances_perm = pd.Series(result.importances_mean, index=names)
  74. total_imp_perm+=forest_importances_perm*acc_score
  75. total_imp_sort=total_imp.sort_values(ascending=False)
  76. total_imp_sort=total_imp_sort[:20]
  77. fig, ax = plt.subplots()
  78. ax.figure.set_size_inches(5, 8)
  79. total_imp_sort.plot.bar(ax=ax)
  80. ax.set_ylabel('Mean decrease in impurity')
  81. fig.tight_layout()
  82. #fig.savefig('/home/user/owncloud/thesis_figures/GW_FI_total_3d.png', dpi=200)
  83. plt.show()
  84. total_imp_perm_sort=total_imp_perm.sort_values(ascending=False)
  85. total_imp_perm_sort=total_imp_perm_sort[:20]
  86. fig, ax = plt.subplots()
  87. ax.figure.set_size_inches(5, 8)
  88. total_imp_perm_sort.plot.bar(ax=ax)
  89. ax.set_ylabel('Mean decrease in impurity')
  90. fig.tight_layout()
  91. #fig.savefig('/home/user/owncloud/thesis_figures/GW_FI_PM_total_3d.png', dpi=200)
  92. plt.show()
  93. ####________________________________
  94. patients=['PB_T2_3_1', 'PB_T2_3_2', 'PB_T2_3_3', 'PB_T2_4_2', 'PB_T2_5_1', 'PB_T2_6_1', 'PB_T2_6_2', 'PB_T3_23_1', 'PB_T3_23_2', 'PB_T3_23_3', 'PB_T3_24_1', 'PB_T3_24_2', 'PB_T3_24_3']
  95. for z in patients:
  96. dill.load_session('/home/user/Documents/Master/CY_'+z+'_data.pkl')
  97. importances = best_model_touch.feature_importances_
  98. std = np.std([tree.feature_importances_ for tree in best_model_touch.estimators_], axis=0)
  99. ranked=np.argsort(importances)[::-1]
  100. std=pd.Series(std)
  101. std=std.reindex(ranked)
  102. names=df_vel_acc.columns.tolist()
  103. names=[sub.replace('acceleration', 'acc') for sub in names]
  104. names=[sub.replace('velocity', 'vel') for sub in names]
  105. names=[sub.replace('angle', 'ang') for sub in names]
  106. names=[sub.replace('right', 'r') for sub in names]
  107. names=[sub.replace('left', 'l') for sub in names]
  108. names=[sub.replace('top', 't') for sub in names]
  109. names=[sub.replace('bottom', 'b') for sub in names]
  110. forest_importances = pd.Series(importances, index=names)
  111. forest_importances=forest_importances.sort_values(ascending=False)
  112. forest_importances=forest_importances[:20]
  113. fig, ax = plt.subplots()
  114. ax.figure.set_size_inches(5, 8)
  115. forest_importances.plot.bar(yerr=np.array(std[:20]/10), ax=ax)
  116. ax.set_ylabel('Mean decrease in impurity')
  117. fig.tight_layout()
  118. #plt.savefig('/home/user/owncloud/thesis_figures/CY_touch_FI_'+z+'_3d.png', dpi=200)
  119. plt.show()
  120. forest_importances = pd.Series(result_touch.importances_mean, index=names)
  121. forest_importances=forest_importances.sort_values(ascending=False)
  122. forest_importances=forest_importances[:20]
  123. fig, ax = plt.subplots()
  124. ax.figure.set_size_inches(5, 8)
  125. forest_importances.plot.bar(yerr=result_touch.importances_std[:20], ax=ax)
  126. ax.set_ylabel('Mean accuracy decrease')
  127. fig.tight_layout()
  128. #fig.savefig('/home/user/owncloud/thesis_figures/CY_touch_FI_PM_'+z+'_3d.png', dpi=200)
  129. plt.show()
  130. ###_____
  131. importances = best_model_drag.feature_importances_
  132. std = np.std([tree.feature_importances_ for tree in best_model_drag.estimators_], axis=0)
  133. ranked=np.argsort(importances)[::-1]
  134. std=pd.Series(std)
  135. std=std.reindex(ranked)
  136. forest_importances = pd.Series(importances, index=names)
  137. forest_importances=forest_importances.sort_values(ascending=False)
  138. forest_importances=forest_importances[:20]
  139. fig, ax = plt.subplots()
  140. ax.figure.set_size_inches(5, 8)
  141. forest_importances.plot.bar(yerr=np.array(std[:20]/10), ax=ax)
  142. ax.set_ylabel('Mean decrease in impurity')
  143. fig.tight_layout()
  144. plt.savefig('/home/user/owncloud/thesis_figures/CY_drag_FI_'+z+'_3d.png', dpi=200)
  145. plt.show()
  146. forest_importances = pd.Series(result_drag.importances_mean, index=names)
  147. forest_importances=forest_importances.sort_values(ascending=False)
  148. forest_importances=forest_importances[:20]
  149. fig, ax = plt.subplots()
  150. ax.figure.set_size_inches(5, 8)
  151. forest_importances.plot.bar(yerr=result_drag.importances_std[:20], ax=ax)
  152. ax.set_ylabel('Mean accuracy decrease')
  153. fig.tight_layout()
  154. fig.savefig('/home/user/owncloud/thesis_figures/CY_drag_FI_PM_'+z+'_3d.png', dpi=200)
  155. plt.show()
  156. patients=['PB_T2_3_1', 'PB_T2_3_2', 'PB_T2_3_3', 'PB_T2_4_2', 'PB_T2_5_1', 'PB_T2_6_1', 'PB_T2_6_2', 'PB_T3_23_1', 'PB_T3_23_2', 'PB_T3_23_3', 'PB_T3_24_1', 'PB_T3_24_2', 'PB_T3_24_3']
  157. for z in patients:
  158. dill.load_session('/home/user/Documents/Master/CY_'+z+'_data.pkl')
  159. names=df_vel_acc.columns.tolist()
  160. names=[sub.replace('acceleration', 'acc') for sub in names]
  161. names=[sub.replace('velocity', 'vel') for sub in names]
  162. names=[sub.replace('angle', 'ang') for sub in names]
  163. names=[sub.replace('right', 'r') for sub in names]
  164. names=[sub.replace('left', 'l') for sub in names]
  165. names=[sub.replace('top', 't') for sub in names]
  166. names=[sub.replace('bottom', 'b') for sub in names]
  167. if z=='PB_T2_3_1':
  168. total_imp_touch=pd.Series(np.zeros((df_vel_acc.shape[1])), index=names)
  169. total_imp_perm_touch=pd.Series(np.zeros((df_vel_acc.shape[1])), index=names)
  170. total_imp_drag=pd.Series(np.zeros((df_vel_acc.shape[1])), index=names)
  171. total_imp_perm_drag=pd.Series(np.zeros((df_vel_acc.shape[1])), index=names)
  172. importances = best_model_touch.feature_importances_
  173. forest_importances_touch = pd.Series(importances, index=names)
  174. total_imp_touch+=forest_importances_touch*acc_score_touch
  175. forest_importances_perm_touch = pd.Series(result_touch.importances_mean, index=names)
  176. total_imp_perm_touch+=forest_importances_perm_touch*acc_score_touch
  177. importances = best_model_drag.feature_importances_
  178. forest_importances_drag = pd.Series(importances, index=names)
  179. total_imp_drag+=forest_importances_drag*acc_score_drag
  180. forest_importances_perm_drag = pd.Series(result_drag.importances_mean, index=names)
  181. total_imp_perm_drag+=forest_importances_perm_drag*acc_score_drag
  182. total_imp_touch_sort=total_imp_touch.sort_values(ascending=False)
  183. total_imp_touch_sort_20=total_imp_touch_sort[:20]
  184. fig, ax = plt.subplots()
  185. ax.figure.set_size_inches(5, 8)
  186. total_imp_touch_sort_20.plot.bar(ax=ax)
  187. ax.set_ylabel('Mean decrease in impurity')
  188. fig.tight_layout()
  189. fig.savefig('/home/user/owncloud/thesis_figures/CY_touch_FI_total_3d.png', dpi=200)
  190. plt.show()
  191. total_imp_perm_touch_sort=total_imp_perm_touch.sort_values(ascending=False)
  192. total_imp_perm_touch_sort_20=total_imp_perm_touch_sort[:20]
  193. fig, ax = plt.subplots()
  194. ax.figure.set_size_inches(5, 8)
  195. total_imp_perm_touch_sort_20.plot.bar(ax=ax)
  196. ax.set_ylabel('Mean decrease in impurity')
  197. fig.tight_layout()
  198. fig.savefig('/home/user/owncloud/thesis_figures/CY_touch_FI_PM_total_3d.png', dpi=200)
  199. plt.show()
  200. total_imp_drag_sort=total_imp_drag.sort_values(ascending=False)
  201. total_imp_drag_sort_20=total_imp_drag_sort[:20]
  202. fig, ax = plt.subplots()
  203. ax.figure.set_size_inches(5, 8)
  204. total_imp_drag_sort_20.plot.bar(ax=ax)
  205. ax.set_ylabel('Mean decrease in impurity')
  206. fig.tight_layout()
  207. fig.savefig('/home/user/owncloud/thesis_figures/CY_drag_FI_total_3d.png', dpi=200)
  208. plt.show()
  209. total_imp_perm_drag_sort=total_imp_perm_drag.sort_values(ascending=False)
  210. total_imp_perm_drag_sort_20=total_imp_perm_drag_sort[:20]
  211. fig, ax = plt.subplots()
  212. ax.figure.set_size_inches(5, 8)
  213. total_imp_perm_drag_sort_20.plot.bar(ax=ax)
  214. ax.set_ylabel('Mean decrease in impurity')
  215. fig.tight_layout()
  216. fig.savefig('/home/user/owncloud/thesis_figures/CY_drag_FI_PM_total_3d.png', dpi=200)
  217. plt.show()
  218. patients=['PB_T2_3_1', 'PB_T2_3_2', 'PB_T2_3_3', 'PB_T2_4_2', 'PB_T2_5_1', 'PB_T2_6_1', 'PB_T2_6_2', 'PB_T3_23_1', 'PB_T3_23_2', 'PB_T3_23_3', 'PB_T3_24_1', 'PB_T3_24_2', 'PB_T3_24_3']
  219. for z in patients:
  220. dill.load_session('/home/user/Documents/Master/GW_2D_'+z+'_data.pkl')
  221. names=df_big.columns.tolist()
  222. names=[sub.replace('acceleration', 'acc') for sub in names]
  223. names=[sub.replace('velocity', 'vel') for sub in names]
  224. names=[sub.replace('angle', 'ang') for sub in names]
  225. names=[sub.replace('right', 'r') for sub in names]
  226. names=[sub.replace('left', 'l') for sub in names]
  227. names=[sub.replace('top', 't') for sub in names]
  228. names=[sub.replace('bottom', 'b') for sub in names]
  229. importances = best_model.feature_importances_
  230. std = np.std([tree.feature_importances_ for tree in best_model.estimators_], axis=0)
  231. ranked=np.argsort(importances)[::-1]
  232. std=pd.Series(std)
  233. std=std.reindex(ranked)
  234. forest_importances = pd.Series(importances, index=names)
  235. forest_importances=forest_importances.sort_values(ascending=False)
  236. forest_importances=forest_importances[:20]
  237. fig, ax= plt.subplots()
  238. ax.figure.set_size_inches(5, 8)
  239. forest_importances.plot.bar(yerr=np.array(std[:20]/10), ax=ax)
  240. ax.set_ylabel('Mean decrease in impurity')
  241. plt.tight_layout()
  242. #plt.savefig('/home/user/owncloud/thesis_figures/GW_FI_'+z+'_2d.png', dpi=200)
  243. plt.show()
  244. forest_importances = pd.Series(result.importances_mean, index=names)
  245. forest_importances=forest_importances.sort_values(ascending=False)
  246. forest_importances=forest_importances[:20]
  247. fig, ax = plt.subplots()
  248. ax.figure.set_size_inches(5, 8)
  249. forest_importances.plot.bar(yerr=result.importances_std[:20], ax=ax)
  250. ax.set_ylabel('Mean accuracy decrease')
  251. fig.tight_layout()
  252. #fig.savefig('/home/user/owncloud/thesis_figures/GW_FI_PM_'+z+'_2d.png', dpi=200)
  253. plt.show()
  254. patients=['PB_T2_3_1', 'PB_T2_3_2', 'PB_T2_3_3', 'PB_T2_4_2', 'PB_T2_5_1', 'PB_T2_6_1', 'PB_T2_6_2', 'PB_T3_23_1', 'PB_T3_23_2', 'PB_T3_23_3', 'PB_T3_24_1', 'PB_T3_24_2', 'PB_T3_24_3']
  255. for z in patients:
  256. dill.load_session('/home/user/Documents/Master/GW_2D_'+z+'_data.pkl')
  257. importances = best_model.feature_importances_
  258. names=df_big.columns.tolist()
  259. names=[sub.replace('acceleration', 'acc') for sub in names]
  260. names=[sub.replace('velocity', 'vel') for sub in names]
  261. names=[sub.replace('angle', 'ang') for sub in names]
  262. names=[sub.replace('right', 'r') for sub in names]
  263. names=[sub.replace('left', 'l') for sub in names]
  264. names=[sub.replace('top', 't') for sub in names]
  265. names=[sub.replace('bottom', 'b') for sub in names]
  266. if z=='PB_T2_3_1':
  267. total_imp=pd.Series(np.zeros((df_vel_acc.shape[1])), index=names)
  268. total_imp_perm=pd.Series(np.zeros((df_vel_acc.shape[1])), index=names)
  269. forest_importances = pd.Series(importances, index=names)
  270. total_imp+=forest_importances*acc_score
  271. forest_importances_perm = pd.Series(result.importances_mean, index=names)
  272. total_imp_perm+=forest_importances_perm*acc_score
  273. total_imp_sort=total_imp.sort_values(ascending=False)
  274. total_imp_sort_20=total_imp_sort[:20]
  275. fig, ax = plt.subplots()
  276. ax.figure.set_size_inches(5, 8)
  277. total_imp_sort_20.plot.bar(ax=ax)
  278. ax.set_ylabel('Mean decrease in impurity')
  279. fig.tight_layout()
  280. #fig.savefig('/home/user/owncloud/thesis_figures/GW_FI_total_2d.png', dpi=200)
  281. plt.show()
  282. total_imp_perm_sort=total_imp_perm.sort_values(ascending=False)
  283. total_imp_perm_sort_20=total_imp_perm_sort[:20]
  284. fig, ax = plt.subplots()
  285. ax.figure.set_size_inches(5, 8)
  286. total_imp_perm_sort_20.plot.bar(ax=ax)
  287. ax.set_ylabel('Mean decrease in impurity')
  288. fig.tight_layout()
  289. #fig.savefig('/home/user/owncloud/thesis_figures/GW_FI_PM_total_2d.png', dpi=200)
  290. plt.show()
  291. patients=['PB_T2_3_1', 'PB_T2_3_2', 'PB_T2_3_3', 'PB_T2_4_2', 'PB_T2_5_1', 'PB_T2_6_1', 'PB_T2_6_2', 'PB_T3_23_1', 'PB_T3_23_2', 'PB_T3_23_3', 'PB_T3_24_1', 'PB_T3_24_2', 'PB_T3_24_3']
  292. z='PB_T3_23_2'
  293. for z in patients:
  294. dill.load_session('/home/user/Documents/Master/CY_2D_'+z+'_data.pkl')
  295. importances = best_model_touch.feature_importances_
  296. std = np.std([tree.feature_importances_ for tree in best_model_touch.estimators_], axis=0)
  297. ranked=np.argsort(importances)[::-1]
  298. std=pd.Series(std)
  299. std=std.reindex(ranked)
  300. names=df_big.columns.tolist()
  301. names=[sub.replace('acceleration', 'acc') for sub in names]
  302. names=[sub.replace('velocity', 'vel') for sub in names]
  303. names=[sub.replace('angle', 'ang') for sub in names]
  304. names=[sub.replace('right', 'r') for sub in names]
  305. names=[sub.replace('left', 'l') for sub in names]
  306. names=[sub.replace('top', 't') for sub in names]
  307. names=[sub.replace('bottom', 'b') for sub in names]
  308. forest_importances = pd.Series(importances, index=names)
  309. forest_importances=forest_importances.sort_values(ascending=False)
  310. forest_importances=forest_importances[:20]
  311. fig, ax = plt.subplots()
  312. ax.figure.set_size_inches(5, 8)
  313. forest_importances.plot.bar(yerr=np.array(std[:20]/10), ax=ax)
  314. ax.set_ylabel('Mean decrease in impurity')
  315. fig.tight_layout()
  316. #plt.savefig('/home/user/owncloud/thesis_figures/CY_touch_FI_'+z+'_2d.png', dpi=200)
  317. plt.show()
  318. forest_importances = pd.Series(result_touch.importances_mean, index=names)
  319. forest_importances=forest_importances.sort_values(ascending=False)
  320. forest_importances=forest_importances[:20]
  321. fig, ax = plt.subplots()
  322. ax.figure.set_size_inches(5, 8)
  323. forest_importances.plot.bar(yerr=result_touch.importances_std[:20], ax=ax)
  324. ax.set_ylabel('Mean accuracy decrease')
  325. fig.tight_layout()
  326. #fig.savefig('/home/user/owncloud/thesis_figures/CY_touch_FI_PM_'+z+'_2d.png', dpi=200)
  327. plt.show()
  328. ###_____
  329. importances = best_model_drag.feature_importances_
  330. std = np.std([tree.feature_importances_ for tree in best_model_drag.estimators_], axis=0)
  331. ranked=np.argsort(importances)[::-1]
  332. std=pd.Series(std)
  333. std=std.reindex(ranked)
  334. forest_importances = pd.Series(importances, index=names)
  335. forest_importances=forest_importances.sort_values(ascending=False)
  336. forest_importances=forest_importances[:20]
  337. fig, ax = plt.subplots()
  338. ax.figure.set_size_inches(5, 8)
  339. forest_importances.plot.bar(yerr=np.array(std[:20]/10), ax=ax)
  340. ax.set_ylabel('Mean decrease in impurity')
  341. fig.tight_layout()
  342. #plt.savefig('/home/user/owncloud/thesis_figures/CY_drag_FI_'+z+'_2d.png', dpi=200)
  343. plt.show()
  344. forest_importances = pd.Series(result_drag.importances_mean, index=names)
  345. forest_importances=forest_importances.sort_values(ascending=False)
  346. forest_importances=forest_importances[:20]
  347. fig, ax = plt.subplots()
  348. ax.figure.set_size_inches(5, 8)
  349. forest_importances.plot.bar(yerr=result_drag.importances_std[:20], ax=ax)
  350. ax.set_ylabel('Mean accuracy decrease')
  351. fig.tight_layout()
  352. #fig.savefig('/home/user/owncloud/thesis_figures/CY_drag_FI_PM_'+z+'_2d.png', dpi=200)
  353. plt.show()
  354. patients=['PB_T2_3_1', 'PB_T2_3_2', 'PB_T2_3_3', 'PB_T2_4_2', 'PB_T2_5_1', 'PB_T2_6_1', 'PB_T2_6_2', 'PB_T3_23_1', 'PB_T3_23_2', 'PB_T3_23_3', 'PB_T3_24_1', 'PB_T3_24_2', 'PB_T3_24_3']
  355. for z in patients:
  356. dill.load_session('/home/user/Documents/Master/CY_2D_'+z+'_data.pkl')
  357. names=df_big.columns.tolist()
  358. names=[sub.replace('acceleration', 'acc') for sub in names]
  359. names=[sub.replace('velocity', 'vel') for sub in names]
  360. names=[sub.replace('angle', 'ang') for sub in names]
  361. names=[sub.replace('right', 'r') for sub in names]
  362. names=[sub.replace('left', 'l') for sub in names]
  363. names=[sub.replace('top', 't') for sub in names]
  364. names=[sub.replace('bottom', 'b') for sub in names]
  365. if z=='PB_T2_3_1':
  366. total_imp_touch=pd.Series(np.zeros((df_vel_acc.shape[1])), index=names)
  367. total_imp_perm_touch=pd.Series(np.zeros((df_vel_acc.shape[1])), index=names)
  368. total_imp_drag=pd.Series(np.zeros((df_vel_acc.shape[1])), index=names)
  369. total_imp_perm_drag=pd.Series(np.zeros((df_vel_acc.shape[1])), index=names)
  370. importances = best_model_touch.feature_importances_
  371. forest_importances_touch = pd.Series(importances, index=names)
  372. total_imp_touch+=forest_importances_touch*acc_score_touch
  373. forest_importances_perm_touch = pd.Series(result_touch.importances_mean, index=names)
  374. total_imp_perm_touch+=forest_importances_perm_touch*acc_score_touch
  375. importances = best_model_drag.feature_importances_
  376. forest_importances_drag = pd.Series(importances, index=names)
  377. total_imp_drag+=forest_importances_drag*acc_score_drag
  378. forest_importances_perm_drag = pd.Series(result_drag.importances_mean, index=names)
  379. total_imp_perm_drag+=forest_importances_perm_drag*acc_score_drag
  380. total_imp_touch_sort=total_imp_touch.sort_values(ascending=False)
  381. total_imp_touch_sort_20=total_imp_touch_sort[:20]
  382. fig, ax = plt.subplots()
  383. ax.figure.set_size_inches(5, 8)
  384. total_imp_touch_sort_20.plot.bar(ax=ax)
  385. ax.set_ylabel('Mean decrease in impurity')
  386. fig.tight_layout()
  387. #fig.savefig('/home/user/owncloud/thesis_figures/CY_touch_FI_total_2d.png', dpi=200)
  388. plt.show()
  389. total_imp_perm_touch_sort=total_imp_perm_touch.sort_values(ascending=False)
  390. total_imp_perm_touch_sort_20=total_imp_perm_touch_sort[:20]
  391. fig, ax = plt.subplots()
  392. ax.figure.set_size_inches(5, 8)
  393. total_imp_perm_touch_sort_20.plot.bar(ax=ax)
  394. ax.set_ylabel('Mean decrease in impurity')
  395. fig.tight_layout()
  396. #fig.savefig('/home/user/owncloud/thesis_figures/CY_touch_FI_PM_total_2d.png', dpi=200)
  397. plt.show()
  398. total_imp_drag_sort=total_imp_drag.sort_values(ascending=False)
  399. total_imp_drag_sort_20=total_imp_drag_sort[:20]
  400. fig, ax = plt.subplots()
  401. ax.figure.set_size_inches(5, 8)
  402. total_imp_drag_sort_20.plot.bar(ax=ax)
  403. ax.set_ylabel('Mean decrease in impurity')
  404. fig.tight_layout()
  405. #fig.savefig('/home/user/owncloud/thesis_figures/CY_drag_FI_total_2d.png', dpi=200)
  406. plt.show()
  407. total_imp_perm_drag_sort=total_imp_perm_drag.sort_values(ascending=False)
  408. total_imp_perm_drag_sort_20=total_imp_perm_drag_sort[:20]
  409. fig, ax = plt.subplots()
  410. ax.figure.set_size_inches(5, 8)
  411. total_imp_perm_drag_sort_20.plot.bar(ax=ax)
  412. ax.set_ylabel('Mean decrease in impurity')
  413. fig.tight_layout()
  414. #fig.savefig('/home/user/owncloud/thesis_figures/CY_drag_FI_PM_total_2d.png', dpi=200)
  415. plt.show()