|
a |
|
b/Random/Random 4.ipynb |
|
|
1 |
{ |
|
|
2 |
"cells": [ |
|
|
3 |
{ |
|
|
4 |
"cell_type": "code", |
|
|
5 |
"execution_count": 3, |
|
|
6 |
"metadata": {}, |
|
|
7 |
"outputs": [ |
|
|
8 |
{ |
|
|
9 |
"name": "stdout", |
|
|
10 |
"output_type": "stream", |
|
|
11 |
"text": [ |
|
|
12 |
"CPU times: user 0 ns, sys: 37 µs, total: 37 µs\n", |
|
|
13 |
"Wall time: 41 µs\n" |
|
|
14 |
] |
|
|
15 |
} |
|
|
16 |
], |
|
|
17 |
"source": [ |
|
|
18 |
"%%time\n", |
|
|
19 |
"import pandas as pd\n", |
|
|
20 |
"import numpy as np\n", |
|
|
21 |
"from sklearn.ensemble import ExtraTreesClassifier\n", |
|
|
22 |
"from sklearn.metrics import classification_report\n", |
|
|
23 |
"from sklearn.model_selection import train_test_split\n", |
|
|
24 |
"from sklearn.ensemble import RandomForestClassifier\n", |
|
|
25 |
"from sklearn.linear_model import LogisticRegression\n", |
|
|
26 |
"\n" |
|
|
27 |
] |
|
|
28 |
}, |
|
|
29 |
{ |
|
|
30 |
"cell_type": "code", |
|
|
31 |
"execution_count": 4, |
|
|
32 |
"metadata": {}, |
|
|
33 |
"outputs": [ |
|
|
34 |
{ |
|
|
35 |
"name": "stdout", |
|
|
36 |
"output_type": "stream", |
|
|
37 |
"text": [ |
|
|
38 |
"CPU times: user 1min 1s, sys: 4.38 s, total: 1min 5s\n", |
|
|
39 |
"Wall time: 1min 18s\n" |
|
|
40 |
] |
|
|
41 |
} |
|
|
42 |
], |
|
|
43 |
"source": [ |
|
|
44 |
"%%time\n", |
|
|
45 |
"df = pd.read_csv(\"master_data.csv\")" |
|
|
46 |
] |
|
|
47 |
}, |
|
|
48 |
{ |
|
|
49 |
"cell_type": "code", |
|
|
50 |
"execution_count": 5, |
|
|
51 |
"metadata": {}, |
|
|
52 |
"outputs": [ |
|
|
53 |
{ |
|
|
54 |
"data": { |
|
|
55 |
"text/plain": [ |
|
|
56 |
"(31470603, 10)" |
|
|
57 |
] |
|
|
58 |
}, |
|
|
59 |
"execution_count": 5, |
|
|
60 |
"metadata": {}, |
|
|
61 |
"output_type": "execute_result" |
|
|
62 |
} |
|
|
63 |
], |
|
|
64 |
"source": [ |
|
|
65 |
"df.shape" |
|
|
66 |
] |
|
|
67 |
}, |
|
|
68 |
{ |
|
|
69 |
"cell_type": "code", |
|
|
70 |
"execution_count": 6, |
|
|
71 |
"metadata": {}, |
|
|
72 |
"outputs": [ |
|
|
73 |
{ |
|
|
74 |
"data": { |
|
|
75 |
"text/plain": [ |
|
|
76 |
"[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17]" |
|
|
77 |
] |
|
|
78 |
}, |
|
|
79 |
"execution_count": 6, |
|
|
80 |
"metadata": {}, |
|
|
81 |
"output_type": "execute_result" |
|
|
82 |
} |
|
|
83 |
], |
|
|
84 |
"source": [ |
|
|
85 |
"df['subject'].unique()\n", |
|
|
86 |
"list_of_subjects=list(df['subject'].unique())\n", |
|
|
87 |
"list_of_subjects.sort()\n", |
|
|
88 |
"list_of_subjects" |
|
|
89 |
] |
|
|
90 |
}, |
|
|
91 |
{ |
|
|
92 |
"cell_type": "code", |
|
|
93 |
"execution_count": 7, |
|
|
94 |
"metadata": {}, |
|
|
95 |
"outputs": [ |
|
|
96 |
{ |
|
|
97 |
"data": { |
|
|
98 |
"text/plain": [ |
|
|
99 |
"['chest_ACC_x',\n", |
|
|
100 |
" 'chest_ACC_y',\n", |
|
|
101 |
" 'chest_ACC_z',\n", |
|
|
102 |
" 'chest_ECG',\n", |
|
|
103 |
" 'chest_EMG',\n", |
|
|
104 |
" 'chest_EDA',\n", |
|
|
105 |
" 'chest_Temp',\n", |
|
|
106 |
" 'chest_Resp']" |
|
|
107 |
] |
|
|
108 |
}, |
|
|
109 |
"execution_count": 7, |
|
|
110 |
"metadata": {}, |
|
|
111 |
"output_type": "execute_result" |
|
|
112 |
} |
|
|
113 |
], |
|
|
114 |
"source": [ |
|
|
115 |
"features=df.columns.tolist()\n", |
|
|
116 |
"to_remove = [fea for fea in features if \"target\" in fea or \"subject\" in fea]\n", |
|
|
117 |
"feature = [x for x in features if x not in to_remove]\n", |
|
|
118 |
"feature" |
|
|
119 |
] |
|
|
120 |
}, |
|
|
121 |
{ |
|
|
122 |
"cell_type": "code", |
|
|
123 |
"execution_count": 8, |
|
|
124 |
"metadata": {}, |
|
|
125 |
"outputs": [ |
|
|
126 |
{ |
|
|
127 |
"data": { |
|
|
128 |
"text/plain": [ |
|
|
129 |
"array([1, 2, 4, 3])" |
|
|
130 |
] |
|
|
131 |
}, |
|
|
132 |
"execution_count": 8, |
|
|
133 |
"metadata": {}, |
|
|
134 |
"output_type": "execute_result" |
|
|
135 |
} |
|
|
136 |
], |
|
|
137 |
"source": [ |
|
|
138 |
"df['target'].unique()" |
|
|
139 |
] |
|
|
140 |
}, |
|
|
141 |
{ |
|
|
142 |
"cell_type": "code", |
|
|
143 |
"execution_count": 9, |
|
|
144 |
"metadata": {}, |
|
|
145 |
"outputs": [ |
|
|
146 |
{ |
|
|
147 |
"name": "stdout", |
|
|
148 |
"output_type": "stream", |
|
|
149 |
"text": [ |
|
|
150 |
"6\n", |
|
|
151 |
"11\n", |
|
|
152 |
"14\n", |
|
|
153 |
"8\n", |
|
|
154 |
"15\n", |
|
|
155 |
"9\n", |
|
|
156 |
"10\n", |
|
|
157 |
"2\n", |
|
|
158 |
"16\n", |
|
|
159 |
"4\n", |
|
|
160 |
"13\n", |
|
|
161 |
"3\n", |
|
|
162 |
"17\n", |
|
|
163 |
"5\n", |
|
|
164 |
"7\n", |
|
|
165 |
"CPU times: user 2.25 s, sys: 663 ms, total: 2.92 s\n", |
|
|
166 |
"Wall time: 3.07 s\n" |
|
|
167 |
] |
|
|
168 |
} |
|
|
169 |
], |
|
|
170 |
"source": [ |
|
|
171 |
"%%time\n", |
|
|
172 |
"test_subject=list(df['subject'].unique())\n", |
|
|
173 |
"for i in test_subject:\n", |
|
|
174 |
" print(i)\n", |
|
|
175 |
" globals()['subject_%s' % i]=df[df['subject'] == i]\n", |
|
|
176 |
"# globals()['subject_%s_train' % i],globals()['subject_%s_test' % i]=train_test_split(globals()['subject_%s' % i], test_size=test_shape)" |
|
|
177 |
] |
|
|
178 |
}, |
|
|
179 |
{ |
|
|
180 |
"cell_type": "code", |
|
|
181 |
"execution_count": 10, |
|
|
182 |
"metadata": {}, |
|
|
183 |
"outputs": [], |
|
|
184 |
"source": [ |
|
|
185 |
"subject_list=[subject_2,subject_3,subject_4,subject_5,subject_6,subject_7,subject_8,subject_9,subject_10,subject_11,subject_13,subject_14,subject_15,subject_16,subject_17]" |
|
|
186 |
] |
|
|
187 |
}, |
|
|
188 |
{ |
|
|
189 |
"cell_type": "code", |
|
|
190 |
"execution_count": 11, |
|
|
191 |
"metadata": {}, |
|
|
192 |
"outputs": [], |
|
|
193 |
"source": [ |
|
|
194 |
"x=[2,3,4,5,6,7,8,9,10,11,13,14,15,16,17]" |
|
|
195 |
] |
|
|
196 |
}, |
|
|
197 |
{ |
|
|
198 |
"cell_type": "code", |
|
|
199 |
"execution_count": 12, |
|
|
200 |
"metadata": {}, |
|
|
201 |
"outputs": [], |
|
|
202 |
"source": [ |
|
|
203 |
"\n", |
|
|
204 |
"for i in range(len(x)):\n", |
|
|
205 |
" \n", |
|
|
206 |
" globals()['df_1_%s' % x[i]]=subject_list[i][subject_list[i]['target']==1]\n", |
|
|
207 |
" globals()['df_2_%s' % x[i]]=subject_list[i][subject_list[i]['target']==2]\n", |
|
|
208 |
" globals()['df_3_%s' % x[i]]=subject_list[i][subject_list[i]['target']==3]\n", |
|
|
209 |
" globals()['df_4_%s' % x[i]]=subject_list[i][subject_list[i]['target']==4]" |
|
|
210 |
] |
|
|
211 |
}, |
|
|
212 |
{ |
|
|
213 |
"cell_type": "code", |
|
|
214 |
"execution_count": 13, |
|
|
215 |
"metadata": {}, |
|
|
216 |
"outputs": [ |
|
|
217 |
{ |
|
|
218 |
"name": "stdout", |
|
|
219 |
"output_type": "stream", |
|
|
220 |
"text": [ |
|
|
221 |
"ExtraTreesClassifier\t LogisticRegression\t RandomForestClassifier\t classification_report\t df\t df_1_10\t df_1_11\t df_1_13\t df_1_14\t \n", |
|
|
222 |
"df_1_15\t df_1_16\t df_1_17\t df_1_2\t df_1_3\t df_1_4\t df_1_5\t df_1_6\t df_1_7\t \n", |
|
|
223 |
"df_1_8\t df_1_9\t df_2_10\t df_2_11\t df_2_13\t df_2_14\t df_2_15\t df_2_16\t df_2_17\t \n", |
|
|
224 |
"df_2_2\t df_2_3\t df_2_4\t df_2_5\t df_2_6\t df_2_7\t df_2_8\t df_2_9\t df_3_10\t \n", |
|
|
225 |
"df_3_11\t df_3_13\t df_3_14\t df_3_15\t df_3_16\t df_3_17\t df_3_2\t df_3_3\t df_3_4\t \n", |
|
|
226 |
"df_3_5\t df_3_6\t df_3_7\t df_3_8\t df_3_9\t df_4_10\t df_4_11\t df_4_13\t df_4_14\t \n", |
|
|
227 |
"df_4_15\t df_4_16\t df_4_17\t df_4_2\t df_4_3\t df_4_4\t df_4_5\t df_4_6\t df_4_7\t \n", |
|
|
228 |
"df_4_8\t df_4_9\t feature\t features\t i\t list_of_subjects\t np\t pd\t subject_10\t \n", |
|
|
229 |
"subject_11\t subject_13\t subject_14\t subject_15\t subject_16\t subject_17\t subject_2\t subject_3\t subject_4\t \n", |
|
|
230 |
"subject_5\t subject_6\t subject_7\t subject_8\t subject_9\t subject_list\t test_subject\t to_remove\t train_test_split\t \n", |
|
|
231 |
"x\t \n" |
|
|
232 |
] |
|
|
233 |
} |
|
|
234 |
], |
|
|
235 |
"source": [ |
|
|
236 |
"who" |
|
|
237 |
] |
|
|
238 |
}, |
|
|
239 |
{ |
|
|
240 |
"cell_type": "code", |
|
|
241 |
"execution_count": 14, |
|
|
242 |
"metadata": {}, |
|
|
243 |
"outputs": [], |
|
|
244 |
"source": [ |
|
|
245 |
"x=[2,3,4,5,6,7,8,9,10,11,13,14,15,16,17]\n", |
|
|
246 |
"cls=[1,2,3,4]" |
|
|
247 |
] |
|
|
248 |
}, |
|
|
249 |
{ |
|
|
250 |
"cell_type": "code", |
|
|
251 |
"execution_count": 15, |
|
|
252 |
"metadata": {}, |
|
|
253 |
"outputs": [ |
|
|
254 |
{ |
|
|
255 |
"data": { |
|
|
256 |
"text/plain": [ |
|
|
257 |
"84000" |
|
|
258 |
] |
|
|
259 |
}, |
|
|
260 |
"execution_count": 15, |
|
|
261 |
"metadata": {}, |
|
|
262 |
"output_type": "execute_result" |
|
|
263 |
} |
|
|
264 |
], |
|
|
265 |
"source": [ |
|
|
266 |
"no_of_rows=int(700*120)\n", |
|
|
267 |
"no_of_rows" |
|
|
268 |
] |
|
|
269 |
}, |
|
|
270 |
{ |
|
|
271 |
"cell_type": "code", |
|
|
272 |
"execution_count": 16, |
|
|
273 |
"metadata": {}, |
|
|
274 |
"outputs": [], |
|
|
275 |
"source": [ |
|
|
276 |
"for i in cls:\n", |
|
|
277 |
" for j in x:\n", |
|
|
278 |
" globals()['df_{}_train_{}'.format(i,j)] = globals()['df_{}_{}'.format(i,j)].iloc[:no_of_rows]\n", |
|
|
279 |
" #globals()['df_{}_train_{}'.format(i,j)],globals()['df_{}_test_{}'.format(i,j)]=train_test_split(globals()['df_{}_{}'.format(i,j)], test_size=0.3)\n", |
|
|
280 |
" #print('subject_'+str(i))\n", |
|
|
281 |
" globals()['df_{}_test_{}'.format(i,j)] = globals()['df_{}_{}'.format(i,j)].iloc[no_of_rows:] " |
|
|
282 |
] |
|
|
283 |
}, |
|
|
284 |
{ |
|
|
285 |
"cell_type": "code", |
|
|
286 |
"execution_count": 17, |
|
|
287 |
"metadata": { |
|
|
288 |
"scrolled": true |
|
|
289 |
}, |
|
|
290 |
"outputs": [], |
|
|
291 |
"source": [ |
|
|
292 |
"concat_list=[]\n", |
|
|
293 |
"for i in cls:\n", |
|
|
294 |
" for j in x:\n", |
|
|
295 |
" concat_list.append(globals()['df_{}_train_{}'.format(i,j)])\n", |
|
|
296 |
"#concat_list[0]" |
|
|
297 |
] |
|
|
298 |
}, |
|
|
299 |
{ |
|
|
300 |
"cell_type": "code", |
|
|
301 |
"execution_count": 22, |
|
|
302 |
"metadata": { |
|
|
303 |
"collapsed": true |
|
|
304 |
}, |
|
|
305 |
"outputs": [ |
|
|
306 |
{ |
|
|
307 |
"data": { |
|
|
308 |
"text/html": [ |
|
|
309 |
"<div>\n", |
|
|
310 |
"<style scoped>\n", |
|
|
311 |
" .dataframe tbody tr th:only-of-type {\n", |
|
|
312 |
" vertical-align: middle;\n", |
|
|
313 |
" }\n", |
|
|
314 |
"\n", |
|
|
315 |
" .dataframe tbody tr th {\n", |
|
|
316 |
" vertical-align: top;\n", |
|
|
317 |
" }\n", |
|
|
318 |
"\n", |
|
|
319 |
" .dataframe thead th {\n", |
|
|
320 |
" text-align: right;\n", |
|
|
321 |
" }\n", |
|
|
322 |
"</style>\n", |
|
|
323 |
"<table border=\"1\" class=\"dataframe\">\n", |
|
|
324 |
" <thead>\n", |
|
|
325 |
" <tr style=\"text-align: right;\">\n", |
|
|
326 |
" <th></th>\n", |
|
|
327 |
" <th>target</th>\n", |
|
|
328 |
" <th>subject</th>\n", |
|
|
329 |
" <th>chest_ACC_x</th>\n", |
|
|
330 |
" <th>chest_ACC_y</th>\n", |
|
|
331 |
" <th>chest_ACC_z</th>\n", |
|
|
332 |
" <th>chest_ECG</th>\n", |
|
|
333 |
" <th>chest_EMG</th>\n", |
|
|
334 |
" <th>chest_EDA</th>\n", |
|
|
335 |
" <th>chest_Temp</th>\n", |
|
|
336 |
" <th>chest_Resp</th>\n", |
|
|
337 |
" </tr>\n", |
|
|
338 |
" </thead>\n", |
|
|
339 |
" <tbody>\n", |
|
|
340 |
" <tr>\n", |
|
|
341 |
" <td>14786800</td>\n", |
|
|
342 |
" <td>1</td>\n", |
|
|
343 |
" <td>2</td>\n", |
|
|
344 |
" <td>0.8914</td>\n", |
|
|
345 |
" <td>-0.1102</td>\n", |
|
|
346 |
" <td>-0.2576</td>\n", |
|
|
347 |
" <td>0.030945</td>\n", |
|
|
348 |
" <td>-0.003708</td>\n", |
|
|
349 |
" <td>5.710983</td>\n", |
|
|
350 |
" <td>29.083618</td>\n", |
|
|
351 |
" <td>1.191711</td>\n", |
|
|
352 |
" </tr>\n", |
|
|
353 |
" <tr>\n", |
|
|
354 |
" <td>14786801</td>\n", |
|
|
355 |
" <td>1</td>\n", |
|
|
356 |
" <td>2</td>\n", |
|
|
357 |
" <td>0.8926</td>\n", |
|
|
358 |
" <td>-0.1086</td>\n", |
|
|
359 |
" <td>-0.2544</td>\n", |
|
|
360 |
" <td>0.033646</td>\n", |
|
|
361 |
" <td>-0.014145</td>\n", |
|
|
362 |
" <td>5.719376</td>\n", |
|
|
363 |
" <td>29.122437</td>\n", |
|
|
364 |
" <td>1.139832</td>\n", |
|
|
365 |
" </tr>\n", |
|
|
366 |
" <tr>\n", |
|
|
367 |
" <td>14786802</td>\n", |
|
|
368 |
" <td>1</td>\n", |
|
|
369 |
" <td>2</td>\n", |
|
|
370 |
" <td>0.8930</td>\n", |
|
|
371 |
" <td>-0.1094</td>\n", |
|
|
372 |
" <td>-0.2580</td>\n", |
|
|
373 |
" <td>0.033005</td>\n", |
|
|
374 |
" <td>0.010208</td>\n", |
|
|
375 |
" <td>5.706406</td>\n", |
|
|
376 |
" <td>29.115234</td>\n", |
|
|
377 |
" <td>1.141357</td>\n", |
|
|
378 |
" </tr>\n", |
|
|
379 |
" <tr>\n", |
|
|
380 |
" <td>14786803</td>\n", |
|
|
381 |
" <td>1</td>\n", |
|
|
382 |
" <td>2</td>\n", |
|
|
383 |
" <td>0.8934</td>\n", |
|
|
384 |
" <td>-0.1082</td>\n", |
|
|
385 |
" <td>-0.2538</td>\n", |
|
|
386 |
" <td>0.031815</td>\n", |
|
|
387 |
" <td>0.012634</td>\n", |
|
|
388 |
" <td>5.712509</td>\n", |
|
|
389 |
" <td>29.126709</td>\n", |
|
|
390 |
" <td>1.155090</td>\n", |
|
|
391 |
" </tr>\n", |
|
|
392 |
" <tr>\n", |
|
|
393 |
" <td>14786804</td>\n", |
|
|
394 |
" <td>1</td>\n", |
|
|
395 |
" <td>2</td>\n", |
|
|
396 |
" <td>0.8930</td>\n", |
|
|
397 |
" <td>-0.1096</td>\n", |
|
|
398 |
" <td>-0.2570</td>\n", |
|
|
399 |
" <td>0.030350</td>\n", |
|
|
400 |
" <td>0.002060</td>\n", |
|
|
401 |
" <td>5.727005</td>\n", |
|
|
402 |
" <td>29.100861</td>\n", |
|
|
403 |
" <td>1.133728</td>\n", |
|
|
404 |
" </tr>\n", |
|
|
405 |
" <tr>\n", |
|
|
406 |
" <td>...</td>\n", |
|
|
407 |
" <td>...</td>\n", |
|
|
408 |
" <td>...</td>\n", |
|
|
409 |
" <td>...</td>\n", |
|
|
410 |
" <td>...</td>\n", |
|
|
411 |
" <td>...</td>\n", |
|
|
412 |
" <td>...</td>\n", |
|
|
413 |
" <td>...</td>\n", |
|
|
414 |
" <td>...</td>\n", |
|
|
415 |
" <td>...</td>\n", |
|
|
416 |
" <td>...</td>\n", |
|
|
417 |
" </tr>\n", |
|
|
418 |
" <tr>\n", |
|
|
419 |
" <td>16809094</td>\n", |
|
|
420 |
" <td>4</td>\n", |
|
|
421 |
" <td>2</td>\n", |
|
|
422 |
" <td>0.4378</td>\n", |
|
|
423 |
" <td>-0.2348</td>\n", |
|
|
424 |
" <td>-0.8380</td>\n", |
|
|
425 |
" <td>-0.182602</td>\n", |
|
|
426 |
" <td>-0.015793</td>\n", |
|
|
427 |
" <td>0.484085</td>\n", |
|
|
428 |
" <td>31.926239</td>\n", |
|
|
429 |
" <td>-1.609802</td>\n", |
|
|
430 |
" </tr>\n", |
|
|
431 |
" <tr>\n", |
|
|
432 |
" <td>16809095</td>\n", |
|
|
433 |
" <td>4</td>\n", |
|
|
434 |
" <td>2</td>\n", |
|
|
435 |
" <td>0.4378</td>\n", |
|
|
436 |
" <td>-0.2338</td>\n", |
|
|
437 |
" <td>-0.8394</td>\n", |
|
|
438 |
" <td>-0.170609</td>\n", |
|
|
439 |
" <td>0.000687</td>\n", |
|
|
440 |
" <td>0.473404</td>\n", |
|
|
441 |
" <td>31.932190</td>\n", |
|
|
442 |
" <td>-1.646423</td>\n", |
|
|
443 |
" </tr>\n", |
|
|
444 |
" <tr>\n", |
|
|
445 |
" <td>16809096</td>\n", |
|
|
446 |
" <td>4</td>\n", |
|
|
447 |
" <td>2</td>\n", |
|
|
448 |
" <td>0.4388</td>\n", |
|
|
449 |
" <td>-0.2338</td>\n", |
|
|
450 |
" <td>-0.8386</td>\n", |
|
|
451 |
" <td>-0.160812</td>\n", |
|
|
452 |
" <td>0.004532</td>\n", |
|
|
453 |
" <td>0.463486</td>\n", |
|
|
454 |
" <td>31.918823</td>\n", |
|
|
455 |
" <td>-1.643372</td>\n", |
|
|
456 |
" </tr>\n", |
|
|
457 |
" <tr>\n", |
|
|
458 |
" <td>16809097</td>\n", |
|
|
459 |
" <td>4</td>\n", |
|
|
460 |
" <td>2</td>\n", |
|
|
461 |
" <td>0.4398</td>\n", |
|
|
462 |
" <td>-0.2374</td>\n", |
|
|
463 |
" <td>-0.8390</td>\n", |
|
|
464 |
" <td>-0.156326</td>\n", |
|
|
465 |
" <td>0.000595</td>\n", |
|
|
466 |
" <td>0.459290</td>\n", |
|
|
467 |
" <td>31.932190</td>\n", |
|
|
468 |
" <td>-1.661682</td>\n", |
|
|
469 |
" </tr>\n", |
|
|
470 |
" <tr>\n", |
|
|
471 |
" <td>16809098</td>\n", |
|
|
472 |
" <td>4</td>\n", |
|
|
473 |
" <td>2</td>\n", |
|
|
474 |
" <td>0.4386</td>\n", |
|
|
475 |
" <td>-0.2366</td>\n", |
|
|
476 |
" <td>-0.8408</td>\n", |
|
|
477 |
" <td>-0.154312</td>\n", |
|
|
478 |
" <td>-0.009201</td>\n", |
|
|
479 |
" <td>0.455475</td>\n", |
|
|
480 |
" <td>31.927704</td>\n", |
|
|
481 |
" <td>-1.646423</td>\n", |
|
|
482 |
" </tr>\n", |
|
|
483 |
" </tbody>\n", |
|
|
484 |
"</table>\n", |
|
|
485 |
"<p>2022299 rows × 10 columns</p>\n", |
|
|
486 |
"</div>" |
|
|
487 |
], |
|
|
488 |
"text/plain": [ |
|
|
489 |
" target subject chest_ACC_x chest_ACC_y chest_ACC_z chest_ECG \\\n", |
|
|
490 |
"14786800 1 2 0.8914 -0.1102 -0.2576 0.030945 \n", |
|
|
491 |
"14786801 1 2 0.8926 -0.1086 -0.2544 0.033646 \n", |
|
|
492 |
"14786802 1 2 0.8930 -0.1094 -0.2580 0.033005 \n", |
|
|
493 |
"14786803 1 2 0.8934 -0.1082 -0.2538 0.031815 \n", |
|
|
494 |
"14786804 1 2 0.8930 -0.1096 -0.2570 0.030350 \n", |
|
|
495 |
"... ... ... ... ... ... ... \n", |
|
|
496 |
"16809094 4 2 0.4378 -0.2348 -0.8380 -0.182602 \n", |
|
|
497 |
"16809095 4 2 0.4378 -0.2338 -0.8394 -0.170609 \n", |
|
|
498 |
"16809096 4 2 0.4388 -0.2338 -0.8386 -0.160812 \n", |
|
|
499 |
"16809097 4 2 0.4398 -0.2374 -0.8390 -0.156326 \n", |
|
|
500 |
"16809098 4 2 0.4386 -0.2366 -0.8408 -0.154312 \n", |
|
|
501 |
"\n", |
|
|
502 |
" chest_EMG chest_EDA chest_Temp chest_Resp \n", |
|
|
503 |
"14786800 -0.003708 5.710983 29.083618 1.191711 \n", |
|
|
504 |
"14786801 -0.014145 5.719376 29.122437 1.139832 \n", |
|
|
505 |
"14786802 0.010208 5.706406 29.115234 1.141357 \n", |
|
|
506 |
"14786803 0.012634 5.712509 29.126709 1.155090 \n", |
|
|
507 |
"14786804 0.002060 5.727005 29.100861 1.133728 \n", |
|
|
508 |
"... ... ... ... ... \n", |
|
|
509 |
"16809094 -0.015793 0.484085 31.926239 -1.609802 \n", |
|
|
510 |
"16809095 0.000687 0.473404 31.932190 -1.646423 \n", |
|
|
511 |
"16809096 0.004532 0.463486 31.918823 -1.643372 \n", |
|
|
512 |
"16809097 0.000595 0.459290 31.932190 -1.661682 \n", |
|
|
513 |
"16809098 -0.009201 0.455475 31.927704 -1.646423 \n", |
|
|
514 |
"\n", |
|
|
515 |
"[2022299 rows x 10 columns]" |
|
|
516 |
] |
|
|
517 |
}, |
|
|
518 |
"execution_count": 22, |
|
|
519 |
"metadata": {}, |
|
|
520 |
"output_type": "execute_result" |
|
|
521 |
} |
|
|
522 |
], |
|
|
523 |
"source": [ |
|
|
524 |
"subject_2" |
|
|
525 |
] |
|
|
526 |
}, |
|
|
527 |
{ |
|
|
528 |
"cell_type": "code", |
|
|
529 |
"execution_count": 18, |
|
|
530 |
"metadata": {}, |
|
|
531 |
"outputs": [ |
|
|
532 |
{ |
|
|
533 |
"data": { |
|
|
534 |
"text/html": [ |
|
|
535 |
"<div>\n", |
|
|
536 |
"<style scoped>\n", |
|
|
537 |
" .dataframe tbody tr th:only-of-type {\n", |
|
|
538 |
" vertical-align: middle;\n", |
|
|
539 |
" }\n", |
|
|
540 |
"\n", |
|
|
541 |
" .dataframe tbody tr th {\n", |
|
|
542 |
" vertical-align: top;\n", |
|
|
543 |
" }\n", |
|
|
544 |
"\n", |
|
|
545 |
" .dataframe thead th {\n", |
|
|
546 |
" text-align: right;\n", |
|
|
547 |
" }\n", |
|
|
548 |
"</style>\n", |
|
|
549 |
"<table border=\"1\" class=\"dataframe\">\n", |
|
|
550 |
" <thead>\n", |
|
|
551 |
" <tr style=\"text-align: right;\">\n", |
|
|
552 |
" <th></th>\n", |
|
|
553 |
" <th>target</th>\n", |
|
|
554 |
" <th>subject</th>\n", |
|
|
555 |
" <th>chest_ACC_x</th>\n", |
|
|
556 |
" <th>chest_ACC_y</th>\n", |
|
|
557 |
" <th>chest_ACC_z</th>\n", |
|
|
558 |
" <th>chest_ECG</th>\n", |
|
|
559 |
" <th>chest_EMG</th>\n", |
|
|
560 |
" <th>chest_EDA</th>\n", |
|
|
561 |
" <th>chest_Temp</th>\n", |
|
|
562 |
" <th>chest_Resp</th>\n", |
|
|
563 |
" </tr>\n", |
|
|
564 |
" </thead>\n", |
|
|
565 |
" <tbody>\n", |
|
|
566 |
" <tr>\n", |
|
|
567 |
" <td>14870800</td>\n", |
|
|
568 |
" <td>1</td>\n", |
|
|
569 |
" <td>2</td>\n", |
|
|
570 |
" <td>0.6296</td>\n", |
|
|
571 |
" <td>-0.1086</td>\n", |
|
|
572 |
" <td>-0.7042</td>\n", |
|
|
573 |
" <td>0.126160</td>\n", |
|
|
574 |
" <td>-0.005585</td>\n", |
|
|
575 |
" <td>3.750992</td>\n", |
|
|
576 |
" <td>28.752167</td>\n", |
|
|
577 |
" <td>-2.301025</td>\n", |
|
|
578 |
" </tr>\n", |
|
|
579 |
" <tr>\n", |
|
|
580 |
" <td>14870801</td>\n", |
|
|
581 |
" <td>1</td>\n", |
|
|
582 |
" <td>2</td>\n", |
|
|
583 |
" <td>0.6296</td>\n", |
|
|
584 |
" <td>-0.1058</td>\n", |
|
|
585 |
" <td>-0.7094</td>\n", |
|
|
586 |
" <td>0.124100</td>\n", |
|
|
587 |
" <td>-0.007004</td>\n", |
|
|
588 |
" <td>3.757477</td>\n", |
|
|
589 |
" <td>28.765045</td>\n", |
|
|
590 |
" <td>-2.740479</td>\n", |
|
|
591 |
" </tr>\n", |
|
|
592 |
" <tr>\n", |
|
|
593 |
" <td>14870802</td>\n", |
|
|
594 |
" <td>1</td>\n", |
|
|
595 |
" <td>2</td>\n", |
|
|
596 |
" <td>0.6292</td>\n", |
|
|
597 |
" <td>-0.1042</td>\n", |
|
|
598 |
" <td>-0.7086</td>\n", |
|
|
599 |
" <td>0.120346</td>\n", |
|
|
600 |
" <td>0.002335</td>\n", |
|
|
601 |
" <td>3.776169</td>\n", |
|
|
602 |
" <td>28.745026</td>\n", |
|
|
603 |
" <td>-2.276611</td>\n", |
|
|
604 |
" </tr>\n", |
|
|
605 |
" <tr>\n", |
|
|
606 |
" <td>14870803</td>\n", |
|
|
607 |
" <td>1</td>\n", |
|
|
608 |
" <td>2</td>\n", |
|
|
609 |
" <td>0.6266</td>\n", |
|
|
610 |
" <td>-0.1022</td>\n", |
|
|
611 |
" <td>-0.7086</td>\n", |
|
|
612 |
" <td>0.113754</td>\n", |
|
|
613 |
" <td>-0.012863</td>\n", |
|
|
614 |
" <td>3.753662</td>\n", |
|
|
615 |
" <td>28.766479</td>\n", |
|
|
616 |
" <td>-2.287292</td>\n", |
|
|
617 |
" </tr>\n", |
|
|
618 |
" <tr>\n", |
|
|
619 |
" <td>14870804</td>\n", |
|
|
620 |
" <td>1</td>\n", |
|
|
621 |
" <td>2</td>\n", |
|
|
622 |
" <td>0.6258</td>\n", |
|
|
623 |
" <td>-0.1022</td>\n", |
|
|
624 |
" <td>-0.7106</td>\n", |
|
|
625 |
" <td>0.109909</td>\n", |
|
|
626 |
" <td>-0.002975</td>\n", |
|
|
627 |
" <td>3.759766</td>\n", |
|
|
628 |
" <td>28.737854</td>\n", |
|
|
629 |
" <td>-2.284241</td>\n", |
|
|
630 |
" </tr>\n", |
|
|
631 |
" <tr>\n", |
|
|
632 |
" <td>...</td>\n", |
|
|
633 |
" <td>...</td>\n", |
|
|
634 |
" <td>...</td>\n", |
|
|
635 |
" <td>...</td>\n", |
|
|
636 |
" <td>...</td>\n", |
|
|
637 |
" <td>...</td>\n", |
|
|
638 |
" <td>...</td>\n", |
|
|
639 |
" <td>...</td>\n", |
|
|
640 |
" <td>...</td>\n", |
|
|
641 |
" <td>...</td>\n", |
|
|
642 |
" <td>...</td>\n", |
|
|
643 |
" </tr>\n", |
|
|
644 |
" <tr>\n", |
|
|
645 |
" <td>15587595</td>\n", |
|
|
646 |
" <td>1</td>\n", |
|
|
647 |
" <td>2</td>\n", |
|
|
648 |
" <td>0.7148</td>\n", |
|
|
649 |
" <td>0.0758</td>\n", |
|
|
650 |
" <td>-0.0428</td>\n", |
|
|
651 |
" <td>0.308167</td>\n", |
|
|
652 |
" <td>0.016617</td>\n", |
|
|
653 |
" <td>1.204681</td>\n", |
|
|
654 |
" <td>29.716492</td>\n", |
|
|
655 |
" <td>-1.144409</td>\n", |
|
|
656 |
" </tr>\n", |
|
|
657 |
" <tr>\n", |
|
|
658 |
" <td>15587596</td>\n", |
|
|
659 |
" <td>1</td>\n", |
|
|
660 |
" <td>2</td>\n", |
|
|
661 |
" <td>0.7144</td>\n", |
|
|
662 |
" <td>0.0670</td>\n", |
|
|
663 |
" <td>-0.0618</td>\n", |
|
|
664 |
" <td>0.332840</td>\n", |
|
|
665 |
" <td>-0.001740</td>\n", |
|
|
666 |
" <td>1.197052</td>\n", |
|
|
667 |
" <td>29.762756</td>\n", |
|
|
668 |
" <td>-1.118469</td>\n", |
|
|
669 |
" </tr>\n", |
|
|
670 |
" <tr>\n", |
|
|
671 |
" <td>15587597</td>\n", |
|
|
672 |
" <td>1</td>\n", |
|
|
673 |
" <td>2</td>\n", |
|
|
674 |
" <td>0.7146</td>\n", |
|
|
675 |
" <td>0.0642</td>\n", |
|
|
676 |
" <td>-0.0726</td>\n", |
|
|
677 |
" <td>0.359528</td>\n", |
|
|
678 |
" <td>-0.005814</td>\n", |
|
|
679 |
" <td>1.200104</td>\n", |
|
|
680 |
" <td>29.715027</td>\n", |
|
|
681 |
" <td>-1.078796</td>\n", |
|
|
682 |
" </tr>\n", |
|
|
683 |
" <tr>\n", |
|
|
684 |
" <td>15587598</td>\n", |
|
|
685 |
" <td>1</td>\n", |
|
|
686 |
" <td>2</td>\n", |
|
|
687 |
" <td>0.7244</td>\n", |
|
|
688 |
" <td>0.0606</td>\n", |
|
|
689 |
" <td>-0.0818</td>\n", |
|
|
690 |
" <td>0.387680</td>\n", |
|
|
691 |
" <td>-0.001602</td>\n", |
|
|
692 |
" <td>1.190948</td>\n", |
|
|
693 |
" <td>29.717896</td>\n", |
|
|
694 |
" <td>-1.025391</td>\n", |
|
|
695 |
" </tr>\n", |
|
|
696 |
" <tr>\n", |
|
|
697 |
" <td>15587599</td>\n", |
|
|
698 |
" <td>1</td>\n", |
|
|
699 |
" <td>2</td>\n", |
|
|
700 |
" <td>0.7282</td>\n", |
|
|
701 |
" <td>0.0506</td>\n", |
|
|
702 |
" <td>-0.0948</td>\n", |
|
|
703 |
" <td>0.415009</td>\n", |
|
|
704 |
" <td>-0.028244</td>\n", |
|
|
705 |
" <td>1.198959</td>\n", |
|
|
706 |
" <td>29.717896</td>\n", |
|
|
707 |
" <td>-0.996399</td>\n", |
|
|
708 |
" </tr>\n", |
|
|
709 |
" </tbody>\n", |
|
|
710 |
"</table>\n", |
|
|
711 |
"<p>716800 rows × 10 columns</p>\n", |
|
|
712 |
"</div>" |
|
|
713 |
], |
|
|
714 |
"text/plain": [ |
|
|
715 |
" target subject chest_ACC_x chest_ACC_y chest_ACC_z chest_ECG \\\n", |
|
|
716 |
"14870800 1 2 0.6296 -0.1086 -0.7042 0.126160 \n", |
|
|
717 |
"14870801 1 2 0.6296 -0.1058 -0.7094 0.124100 \n", |
|
|
718 |
"14870802 1 2 0.6292 -0.1042 -0.7086 0.120346 \n", |
|
|
719 |
"14870803 1 2 0.6266 -0.1022 -0.7086 0.113754 \n", |
|
|
720 |
"14870804 1 2 0.6258 -0.1022 -0.7106 0.109909 \n", |
|
|
721 |
"... ... ... ... ... ... ... \n", |
|
|
722 |
"15587595 1 2 0.7148 0.0758 -0.0428 0.308167 \n", |
|
|
723 |
"15587596 1 2 0.7144 0.0670 -0.0618 0.332840 \n", |
|
|
724 |
"15587597 1 2 0.7146 0.0642 -0.0726 0.359528 \n", |
|
|
725 |
"15587598 1 2 0.7244 0.0606 -0.0818 0.387680 \n", |
|
|
726 |
"15587599 1 2 0.7282 0.0506 -0.0948 0.415009 \n", |
|
|
727 |
"\n", |
|
|
728 |
" chest_EMG chest_EDA chest_Temp chest_Resp \n", |
|
|
729 |
"14870800 -0.005585 3.750992 28.752167 -2.301025 \n", |
|
|
730 |
"14870801 -0.007004 3.757477 28.765045 -2.740479 \n", |
|
|
731 |
"14870802 0.002335 3.776169 28.745026 -2.276611 \n", |
|
|
732 |
"14870803 -0.012863 3.753662 28.766479 -2.287292 \n", |
|
|
733 |
"14870804 -0.002975 3.759766 28.737854 -2.284241 \n", |
|
|
734 |
"... ... ... ... ... \n", |
|
|
735 |
"15587595 0.016617 1.204681 29.716492 -1.144409 \n", |
|
|
736 |
"15587596 -0.001740 1.197052 29.762756 -1.118469 \n", |
|
|
737 |
"15587597 -0.005814 1.200104 29.715027 -1.078796 \n", |
|
|
738 |
"15587598 -0.001602 1.190948 29.717896 -1.025391 \n", |
|
|
739 |
"15587599 -0.028244 1.198959 29.717896 -0.996399 \n", |
|
|
740 |
"\n", |
|
|
741 |
"[716800 rows x 10 columns]" |
|
|
742 |
] |
|
|
743 |
}, |
|
|
744 |
"execution_count": 18, |
|
|
745 |
"metadata": {}, |
|
|
746 |
"output_type": "execute_result" |
|
|
747 |
} |
|
|
748 |
], |
|
|
749 |
"source": [ |
|
|
750 |
"concat_list1=[]\n", |
|
|
751 |
"for i in cls:\n", |
|
|
752 |
" for j in x:\n", |
|
|
753 |
" concat_list1.append(globals()['df_{}_test_{}'.format(i,j)])\n", |
|
|
754 |
"concat_list1[0]" |
|
|
755 |
] |
|
|
756 |
}, |
|
|
757 |
{ |
|
|
758 |
"cell_type": "code", |
|
|
759 |
"execution_count": 19, |
|
|
760 |
"metadata": { |
|
|
761 |
"scrolled": true |
|
|
762 |
}, |
|
|
763 |
"outputs": [ |
|
|
764 |
{ |
|
|
765 |
"data": { |
|
|
766 |
"text/plain": [ |
|
|
767 |
"(5040000, 10)" |
|
|
768 |
] |
|
|
769 |
}, |
|
|
770 |
"execution_count": 19, |
|
|
771 |
"metadata": {}, |
|
|
772 |
"output_type": "execute_result" |
|
|
773 |
} |
|
|
774 |
], |
|
|
775 |
"source": [ |
|
|
776 |
"train_df=pd.concat(concat_list)\n", |
|
|
777 |
"train_df.shape" |
|
|
778 |
] |
|
|
779 |
}, |
|
|
780 |
{ |
|
|
781 |
"cell_type": "code", |
|
|
782 |
"execution_count": 20, |
|
|
783 |
"metadata": {}, |
|
|
784 |
"outputs": [ |
|
|
785 |
{ |
|
|
786 |
"data": { |
|
|
787 |
"text/plain": [ |
|
|
788 |
"4 1260000\n", |
|
|
789 |
"3 1260000\n", |
|
|
790 |
"2 1260000\n", |
|
|
791 |
"1 1260000\n", |
|
|
792 |
"Name: target, dtype: int64" |
|
|
793 |
] |
|
|
794 |
}, |
|
|
795 |
"execution_count": 20, |
|
|
796 |
"metadata": {}, |
|
|
797 |
"output_type": "execute_result" |
|
|
798 |
} |
|
|
799 |
], |
|
|
800 |
"source": [ |
|
|
801 |
"train_df.target.value_counts()" |
|
|
802 |
] |
|
|
803 |
}, |
|
|
804 |
{ |
|
|
805 |
"cell_type": "code", |
|
|
806 |
"execution_count": 21, |
|
|
807 |
"metadata": { |
|
|
808 |
"scrolled": true |
|
|
809 |
}, |
|
|
810 |
"outputs": [ |
|
|
811 |
{ |
|
|
812 |
"data": { |
|
|
813 |
"text/plain": [ |
|
|
814 |
"15" |
|
|
815 |
] |
|
|
816 |
}, |
|
|
817 |
"execution_count": 21, |
|
|
818 |
"metadata": {}, |
|
|
819 |
"output_type": "execute_result" |
|
|
820 |
} |
|
|
821 |
], |
|
|
822 |
"source": [ |
|
|
823 |
"len(train_df.subject.unique())" |
|
|
824 |
] |
|
|
825 |
}, |
|
|
826 |
{ |
|
|
827 |
"cell_type": "code", |
|
|
828 |
"execution_count": 22, |
|
|
829 |
"metadata": {}, |
|
|
830 |
"outputs": [ |
|
|
831 |
{ |
|
|
832 |
"data": { |
|
|
833 |
"text/plain": [ |
|
|
834 |
"(26430603, 10)" |
|
|
835 |
] |
|
|
836 |
}, |
|
|
837 |
"execution_count": 22, |
|
|
838 |
"metadata": {}, |
|
|
839 |
"output_type": "execute_result" |
|
|
840 |
} |
|
|
841 |
], |
|
|
842 |
"source": [ |
|
|
843 |
"test_df=pd.concat(concat_list1)\n", |
|
|
844 |
"test_df.shape" |
|
|
845 |
] |
|
|
846 |
}, |
|
|
847 |
{ |
|
|
848 |
"cell_type": "code", |
|
|
849 |
"execution_count": 23, |
|
|
850 |
"metadata": {}, |
|
|
851 |
"outputs": [], |
|
|
852 |
"source": [ |
|
|
853 |
"for i in test_subject:\n", |
|
|
854 |
" del(globals()['subject_%s' % i])\n", |
|
|
855 |
" \n", |
|
|
856 |
"for i in range(len(x)): \n", |
|
|
857 |
" del(globals()['df_1_%s' % x[i]])\n", |
|
|
858 |
" del(globals()['df_2_%s' % x[i]])\n", |
|
|
859 |
" del(globals()['df_3_%s' % x[i]])\n", |
|
|
860 |
" del(globals()['df_4_%s' % x[i]])\n", |
|
|
861 |
"for i in cls:\n", |
|
|
862 |
" for j in x:\n", |
|
|
863 |
" del(globals()['df_{}_train_{}'.format(i,j)])\n", |
|
|
864 |
" del(globals()['df_{}_test_{}'.format(i,j)])\n", |
|
|
865 |
"del df" |
|
|
866 |
] |
|
|
867 |
}, |
|
|
868 |
{ |
|
|
869 |
"cell_type": "code", |
|
|
870 |
"execution_count": null, |
|
|
871 |
"metadata": {}, |
|
|
872 |
"outputs": [], |
|
|
873 |
"source": [ |
|
|
874 |
"who" |
|
|
875 |
] |
|
|
876 |
}, |
|
|
877 |
{ |
|
|
878 |
"cell_type": "code", |
|
|
879 |
"execution_count": null, |
|
|
880 |
"metadata": {}, |
|
|
881 |
"outputs": [], |
|
|
882 |
"source": [ |
|
|
883 |
"%%time\n", |
|
|
884 |
"et = ExtraTreesClassifier(n_estimators=50, n_jobs=10, verbose=2,random_state=0)" |
|
|
885 |
] |
|
|
886 |
}, |
|
|
887 |
{ |
|
|
888 |
"cell_type": "code", |
|
|
889 |
"execution_count": null, |
|
|
890 |
"metadata": {}, |
|
|
891 |
"outputs": [], |
|
|
892 |
"source": [ |
|
|
893 |
"#et = RandomForestClassifier(n_estimators=100, n_jobs=10, verbose=2,random_state=0)" |
|
|
894 |
] |
|
|
895 |
}, |
|
|
896 |
{ |
|
|
897 |
"cell_type": "code", |
|
|
898 |
"execution_count": null, |
|
|
899 |
"metadata": { |
|
|
900 |
"scrolled": true |
|
|
901 |
}, |
|
|
902 |
"outputs": [], |
|
|
903 |
"source": [ |
|
|
904 |
"et.fit(train_df[feature],train_df['target'])" |
|
|
905 |
] |
|
|
906 |
}, |
|
|
907 |
{ |
|
|
908 |
"cell_type": "code", |
|
|
909 |
"execution_count": null, |
|
|
910 |
"metadata": {}, |
|
|
911 |
"outputs": [], |
|
|
912 |
"source": [ |
|
|
913 |
"%%time \n", |
|
|
914 |
"y_pred=et.predict(test_df[feature])" |
|
|
915 |
] |
|
|
916 |
}, |
|
|
917 |
{ |
|
|
918 |
"cell_type": "code", |
|
|
919 |
"execution_count": null, |
|
|
920 |
"metadata": {}, |
|
|
921 |
"outputs": [], |
|
|
922 |
"source": [ |
|
|
923 |
"print(classification_report(test_df['target'], y_pred))" |
|
|
924 |
] |
|
|
925 |
}, |
|
|
926 |
{ |
|
|
927 |
"cell_type": "code", |
|
|
928 |
"execution_count": null, |
|
|
929 |
"metadata": {}, |
|
|
930 |
"outputs": [], |
|
|
931 |
"source": [ |
|
|
932 |
"#train_df.to_csv('1_min_train.csv')" |
|
|
933 |
] |
|
|
934 |
}, |
|
|
935 |
{ |
|
|
936 |
"cell_type": "code", |
|
|
937 |
"execution_count": null, |
|
|
938 |
"metadata": {}, |
|
|
939 |
"outputs": [], |
|
|
940 |
"source": [ |
|
|
941 |
"#test_df.to_csv('1_min_test.csv')" |
|
|
942 |
] |
|
|
943 |
}, |
|
|
944 |
{ |
|
|
945 |
"cell_type": "code", |
|
|
946 |
"execution_count": 33, |
|
|
947 |
"metadata": {}, |
|
|
948 |
"outputs": [], |
|
|
949 |
"source": [ |
|
|
950 |
"# train_df.to_csv('30_sec_train.csv')" |
|
|
951 |
] |
|
|
952 |
}, |
|
|
953 |
{ |
|
|
954 |
"cell_type": "code", |
|
|
955 |
"execution_count": 34, |
|
|
956 |
"metadata": {}, |
|
|
957 |
"outputs": [], |
|
|
958 |
"source": [ |
|
|
959 |
"# test_df.to_csv('30_sec_test.csv')" |
|
|
960 |
] |
|
|
961 |
}, |
|
|
962 |
{ |
|
|
963 |
"cell_type": "code", |
|
|
964 |
"execution_count": 24, |
|
|
965 |
"metadata": {}, |
|
|
966 |
"outputs": [], |
|
|
967 |
"source": [ |
|
|
968 |
"train_df.to_csv('2_min_train.csv')" |
|
|
969 |
] |
|
|
970 |
}, |
|
|
971 |
{ |
|
|
972 |
"cell_type": "code", |
|
|
973 |
"execution_count": 25, |
|
|
974 |
"metadata": {}, |
|
|
975 |
"outputs": [], |
|
|
976 |
"source": [ |
|
|
977 |
"test_df.to_csv('2_min_test.csv')s" |
|
|
978 |
] |
|
|
979 |
}, |
|
|
980 |
{ |
|
|
981 |
"cell_type": "code", |
|
|
982 |
"execution_count": null, |
|
|
983 |
"metadata": {}, |
|
|
984 |
"outputs": [], |
|
|
985 |
"source": [ |
|
|
986 |
"from sklearn.model_selection import cross_val_score\n", |
|
|
987 |
"scores = cross_val_score(et, train_df[feature],train_df['target'], cv=4)\n", |
|
|
988 |
"print(scores)" |
|
|
989 |
] |
|
|
990 |
}, |
|
|
991 |
{ |
|
|
992 |
"cell_type": "code", |
|
|
993 |
"execution_count": 27, |
|
|
994 |
"metadata": { |
|
|
995 |
"scrolled": true |
|
|
996 |
}, |
|
|
997 |
"outputs": [ |
|
|
998 |
{ |
|
|
999 |
"name": "stdout", |
|
|
1000 |
"output_type": "stream", |
|
|
1001 |
"text": [ |
|
|
1002 |
"Fitting 10 folds for each of 6 candidates, totalling 60 fits\n" |
|
|
1003 |
] |
|
|
1004 |
}, |
|
|
1005 |
{ |
|
|
1006 |
"name": "stderr", |
|
|
1007 |
"output_type": "stream", |
|
|
1008 |
"text": [ |
|
|
1009 |
"[Parallel(n_jobs=1)]: Using backend SequentialBackend with 1 concurrent workers.\n" |
|
|
1010 |
] |
|
|
1011 |
}, |
|
|
1012 |
{ |
|
|
1013 |
"name": "stdout", |
|
|
1014 |
"output_type": "stream", |
|
|
1015 |
"text": [ |
|
|
1016 |
"[CV] n_neighbors=1 ...................................................\n", |
|
|
1017 |
"[CV] .................................... n_neighbors=1, total= 17.2s\n", |
|
|
1018 |
"[CV] n_neighbors=1 ...................................................\n" |
|
|
1019 |
] |
|
|
1020 |
}, |
|
|
1021 |
{ |
|
|
1022 |
"name": "stderr", |
|
|
1023 |
"output_type": "stream", |
|
|
1024 |
"text": [ |
|
|
1025 |
"[Parallel(n_jobs=1)]: Done 1 out of 1 | elapsed: 17.2s remaining: 0.0s\n" |
|
|
1026 |
] |
|
|
1027 |
}, |
|
|
1028 |
{ |
|
|
1029 |
"name": "stdout", |
|
|
1030 |
"output_type": "stream", |
|
|
1031 |
"text": [ |
|
|
1032 |
"[CV] .................................... n_neighbors=1, total= 22.0s\n", |
|
|
1033 |
"[CV] n_neighbors=1 ...................................................\n", |
|
|
1034 |
"[CV] .................................... n_neighbors=1, total= 18.1s\n", |
|
|
1035 |
"[CV] n_neighbors=1 ...................................................\n", |
|
|
1036 |
"[CV] .................................... n_neighbors=1, total= 13.1s\n", |
|
|
1037 |
"[CV] n_neighbors=1 ...................................................\n", |
|
|
1038 |
"[CV] .................................... n_neighbors=1, total= 21.9s\n", |
|
|
1039 |
"[CV] n_neighbors=1 ...................................................\n", |
|
|
1040 |
"[CV] .................................... n_neighbors=1, total= 30.5s\n", |
|
|
1041 |
"[CV] n_neighbors=1 ...................................................\n", |
|
|
1042 |
"[CV] .................................... n_neighbors=1, total= 17.4s\n", |
|
|
1043 |
"[CV] n_neighbors=1 ...................................................\n", |
|
|
1044 |
"[CV] .................................... n_neighbors=1, total= 19.3s\n", |
|
|
1045 |
"[CV] n_neighbors=1 ...................................................\n", |
|
|
1046 |
"[CV] .................................... n_neighbors=1, total= 21.8s\n", |
|
|
1047 |
"[CV] n_neighbors=1 ...................................................\n", |
|
|
1048 |
"[CV] .................................... n_neighbors=1, total= 21.4s\n", |
|
|
1049 |
"[CV] n_neighbors=3 ...................................................\n", |
|
|
1050 |
"[CV] .................................... n_neighbors=3, total= 21.4s\n", |
|
|
1051 |
"[CV] n_neighbors=3 ...................................................\n", |
|
|
1052 |
"[CV] .................................... n_neighbors=3, total= 28.9s\n", |
|
|
1053 |
"[CV] n_neighbors=3 ...................................................\n", |
|
|
1054 |
"[CV] .................................... n_neighbors=3, total= 20.3s\n", |
|
|
1055 |
"[CV] n_neighbors=3 ...................................................\n", |
|
|
1056 |
"[CV] .................................... n_neighbors=3, total= 15.2s\n", |
|
|
1057 |
"[CV] n_neighbors=3 ...................................................\n", |
|
|
1058 |
"[CV] .................................... n_neighbors=3, total= 21.3s\n", |
|
|
1059 |
"[CV] n_neighbors=3 ...................................................\n", |
|
|
1060 |
"[CV] .................................... n_neighbors=3, total= 24.5s\n", |
|
|
1061 |
"[CV] n_neighbors=3 ...................................................\n", |
|
|
1062 |
"[CV] .................................... n_neighbors=3, total= 19.0s\n", |
|
|
1063 |
"[CV] n_neighbors=3 ...................................................\n", |
|
|
1064 |
"[CV] .................................... n_neighbors=3, total= 20.7s\n", |
|
|
1065 |
"[CV] n_neighbors=3 ...................................................\n", |
|
|
1066 |
"[CV] .................................... n_neighbors=3, total= 24.1s\n", |
|
|
1067 |
"[CV] n_neighbors=3 ...................................................\n", |
|
|
1068 |
"[CV] .................................... n_neighbors=3, total= 23.5s\n", |
|
|
1069 |
"[CV] n_neighbors=5 ...................................................\n", |
|
|
1070 |
"[CV] .................................... n_neighbors=5, total= 22.2s\n", |
|
|
1071 |
"[CV] n_neighbors=5 ...................................................\n", |
|
|
1072 |
"[CV] .................................... n_neighbors=5, total= 24.9s\n", |
|
|
1073 |
"[CV] n_neighbors=5 ...................................................\n", |
|
|
1074 |
"[CV] .................................... n_neighbors=5, total= 21.1s\n", |
|
|
1075 |
"[CV] n_neighbors=5 ...................................................\n", |
|
|
1076 |
"[CV] .................................... n_neighbors=5, total= 13.9s\n", |
|
|
1077 |
"[CV] n_neighbors=5 ...................................................\n", |
|
|
1078 |
"[CV] .................................... n_neighbors=5, total= 22.0s\n", |
|
|
1079 |
"[CV] n_neighbors=5 ...................................................\n", |
|
|
1080 |
"[CV] .................................... n_neighbors=5, total= 27.2s\n", |
|
|
1081 |
"[CV] n_neighbors=5 ...................................................\n", |
|
|
1082 |
"[CV] .................................... n_neighbors=5, total= 19.0s\n", |
|
|
1083 |
"[CV] n_neighbors=5 ...................................................\n", |
|
|
1084 |
"[CV] .................................... n_neighbors=5, total= 21.3s\n", |
|
|
1085 |
"[CV] n_neighbors=5 ...................................................\n", |
|
|
1086 |
"[CV] .................................... n_neighbors=5, total= 25.0s\n", |
|
|
1087 |
"[CV] n_neighbors=5 ...................................................\n", |
|
|
1088 |
"[CV] .................................... n_neighbors=5, total= 24.3s\n", |
|
|
1089 |
"[CV] n_neighbors=7 ...................................................\n", |
|
|
1090 |
"[CV] .................................... n_neighbors=7, total= 22.7s\n", |
|
|
1091 |
"[CV] n_neighbors=7 ...................................................\n", |
|
|
1092 |
"[CV] .................................... n_neighbors=7, total= 25.2s\n", |
|
|
1093 |
"[CV] n_neighbors=7 ...................................................\n", |
|
|
1094 |
"[CV] .................................... n_neighbors=7, total= 21.6s\n", |
|
|
1095 |
"[CV] n_neighbors=7 ...................................................\n", |
|
|
1096 |
"[CV] .................................... n_neighbors=7, total= 13.8s\n", |
|
|
1097 |
"[CV] n_neighbors=7 ...................................................\n", |
|
|
1098 |
"[CV] .................................... n_neighbors=7, total= 22.1s\n", |
|
|
1099 |
"[CV] n_neighbors=7 ...................................................\n", |
|
|
1100 |
"[CV] .................................... n_neighbors=7, total= 28.4s\n", |
|
|
1101 |
"[CV] n_neighbors=7 ...................................................\n", |
|
|
1102 |
"[CV] .................................... n_neighbors=7, total= 19.4s\n", |
|
|
1103 |
"[CV] n_neighbors=7 ...................................................\n", |
|
|
1104 |
"[CV] .................................... n_neighbors=7, total= 21.6s\n", |
|
|
1105 |
"[CV] n_neighbors=7 ...................................................\n", |
|
|
1106 |
"[CV] .................................... n_neighbors=7, total= 25.3s\n", |
|
|
1107 |
"[CV] n_neighbors=7 ...................................................\n", |
|
|
1108 |
"[CV] .................................... n_neighbors=7, total= 24.4s\n", |
|
|
1109 |
"[CV] n_neighbors=9 ...................................................\n", |
|
|
1110 |
"[CV] .................................... n_neighbors=9, total= 23.3s\n", |
|
|
1111 |
"[CV] n_neighbors=9 ...................................................\n", |
|
|
1112 |
"[CV] .................................... n_neighbors=9, total= 25.8s\n", |
|
|
1113 |
"[CV] n_neighbors=9 ...................................................\n", |
|
|
1114 |
"[CV] .................................... n_neighbors=9, total= 22.1s\n", |
|
|
1115 |
"[CV] n_neighbors=9 ...................................................\n", |
|
|
1116 |
"[CV] .................................... n_neighbors=9, total= 13.8s\n", |
|
|
1117 |
"[CV] n_neighbors=9 ...................................................\n", |
|
|
1118 |
"[CV] .................................... n_neighbors=9, total= 22.5s\n", |
|
|
1119 |
"[CV] n_neighbors=9 ...................................................\n", |
|
|
1120 |
"[CV] .................................... n_neighbors=9, total= 28.0s\n", |
|
|
1121 |
"[CV] n_neighbors=9 ...................................................\n", |
|
|
1122 |
"[CV] .................................... n_neighbors=9, total= 21.1s\n", |
|
|
1123 |
"[CV] n_neighbors=9 ...................................................\n", |
|
|
1124 |
"[CV] .................................... n_neighbors=9, total= 22.1s\n", |
|
|
1125 |
"[CV] n_neighbors=9 ...................................................\n", |
|
|
1126 |
"[CV] .................................... n_neighbors=9, total= 26.2s\n", |
|
|
1127 |
"[CV] n_neighbors=9 ...................................................\n", |
|
|
1128 |
"[CV] .................................... n_neighbors=9, total= 24.9s\n", |
|
|
1129 |
"[CV] n_neighbors=11 ..................................................\n", |
|
|
1130 |
"[CV] ................................... n_neighbors=11, total= 24.0s\n", |
|
|
1131 |
"[CV] n_neighbors=11 ..................................................\n", |
|
|
1132 |
"[CV] ................................... n_neighbors=11, total= 26.5s\n", |
|
|
1133 |
"[CV] n_neighbors=11 ..................................................\n", |
|
|
1134 |
"[CV] ................................... n_neighbors=11, total= 29.7s\n", |
|
|
1135 |
"[CV] n_neighbors=11 ..................................................\n", |
|
|
1136 |
"[CV] ................................... n_neighbors=11, total= 14.2s\n", |
|
|
1137 |
"[CV] n_neighbors=11 ..................................................\n", |
|
|
1138 |
"[CV] ................................... n_neighbors=11, total= 23.2s\n", |
|
|
1139 |
"[CV] n_neighbors=11 ..................................................\n", |
|
|
1140 |
"[CV] ................................... n_neighbors=11, total= 28.7s\n", |
|
|
1141 |
"[CV] n_neighbors=11 ..................................................\n", |
|
|
1142 |
"[CV] ................................... n_neighbors=11, total= 21.7s\n", |
|
|
1143 |
"[CV] n_neighbors=11 ..................................................\n", |
|
|
1144 |
"[CV] ................................... n_neighbors=11, total= 22.7s\n", |
|
|
1145 |
"[CV] n_neighbors=11 ..................................................\n", |
|
|
1146 |
"[CV] ................................... n_neighbors=11, total= 27.1s\n", |
|
|
1147 |
"[CV] n_neighbors=11 ..................................................\n" |
|
|
1148 |
] |
|
|
1149 |
}, |
|
|
1150 |
{ |
|
|
1151 |
"name": "stdout", |
|
|
1152 |
"output_type": "stream", |
|
|
1153 |
"text": [ |
|
|
1154 |
"[CV] ................................... n_neighbors=11, total= 25.6s\n" |
|
|
1155 |
] |
|
|
1156 |
}, |
|
|
1157 |
{ |
|
|
1158 |
"name": "stderr", |
|
|
1159 |
"output_type": "stream", |
|
|
1160 |
"text": [ |
|
|
1161 |
"[Parallel(n_jobs=1)]: Done 60 out of 60 | elapsed: 22.4min finished\n" |
|
|
1162 |
] |
|
|
1163 |
}, |
|
|
1164 |
{ |
|
|
1165 |
"data": { |
|
|
1166 |
"text/plain": [ |
|
|
1167 |
"GridSearchCV(cv=10, error_score='raise-deprecating',\n", |
|
|
1168 |
" estimator=KNeighborsClassifier(algorithm='auto', leaf_size=30,\n", |
|
|
1169 |
" metric='minkowski',\n", |
|
|
1170 |
" metric_params=None, n_jobs=None,\n", |
|
|
1171 |
" n_neighbors=5, p=2,\n", |
|
|
1172 |
" weights='uniform'),\n", |
|
|
1173 |
" iid='warn', n_jobs=None,\n", |
|
|
1174 |
" param_grid={'n_neighbors': [1, 3, 5, 7, 9, 11]},\n", |
|
|
1175 |
" pre_dispatch='2*n_jobs', refit=True, return_train_score=False,\n", |
|
|
1176 |
" scoring=None, verbose=2)" |
|
|
1177 |
] |
|
|
1178 |
}, |
|
|
1179 |
"execution_count": 27, |
|
|
1180 |
"metadata": {}, |
|
|
1181 |
"output_type": "execute_result" |
|
|
1182 |
} |
|
|
1183 |
], |
|
|
1184 |
"source": [ |
|
|
1185 |
"from sklearn.model_selection import GridSearchCV\n", |
|
|
1186 |
"from sklearn.neighbors import KNeighborsClassifier\n", |
|
|
1187 |
"# param_grid = { \n", |
|
|
1188 |
"# 'n_estimators': [20],\n", |
|
|
1189 |
"# 'max_features': ['auto'],\n", |
|
|
1190 |
"# # 'max_depth' : [4,5,6,7,8],\n", |
|
|
1191 |
"# 'criterion' :['gini', 'entropy']\n", |
|
|
1192 |
"# }\n", |
|
|
1193 |
"\n", |
|
|
1194 |
"param_grid = { \n", |
|
|
1195 |
" 'n_neighbors': [1,3,5,7,9,11]\n", |
|
|
1196 |
"}\n", |
|
|
1197 |
"\n", |
|
|
1198 |
"clf = KNeighborsClassifier()\n", |
|
|
1199 |
"\n", |
|
|
1200 |
"CV_rfc = GridSearchCV(estimator=clf, param_grid=param_grid, cv= 10,verbose=2)\n", |
|
|
1201 |
"CV_rfc.fit(train_df[feature],train_df['target'])" |
|
|
1202 |
] |
|
|
1203 |
}, |
|
|
1204 |
{ |
|
|
1205 |
"cell_type": "code", |
|
|
1206 |
"execution_count": 28, |
|
|
1207 |
"metadata": {}, |
|
|
1208 |
"outputs": [ |
|
|
1209 |
{ |
|
|
1210 |
"data": { |
|
|
1211 |
"text/plain": [ |
|
|
1212 |
"{'n_neighbors': 1}" |
|
|
1213 |
] |
|
|
1214 |
}, |
|
|
1215 |
"execution_count": 28, |
|
|
1216 |
"metadata": {}, |
|
|
1217 |
"output_type": "execute_result" |
|
|
1218 |
} |
|
|
1219 |
], |
|
|
1220 |
"source": [ |
|
|
1221 |
"CV_rfc.best_params_" |
|
|
1222 |
] |
|
|
1223 |
}, |
|
|
1224 |
{ |
|
|
1225 |
"cell_type": "code", |
|
|
1226 |
"execution_count": null, |
|
|
1227 |
"metadata": {}, |
|
|
1228 |
"outputs": [], |
|
|
1229 |
"source": [ |
|
|
1230 |
"%%time\n", |
|
|
1231 |
"et = ExtraTreesClassifier(n_estimators=20, n_jobs=10, verbose=2,random_state=0)" |
|
|
1232 |
] |
|
|
1233 |
}, |
|
|
1234 |
{ |
|
|
1235 |
"cell_type": "code", |
|
|
1236 |
"execution_count": null, |
|
|
1237 |
"metadata": {}, |
|
|
1238 |
"outputs": [], |
|
|
1239 |
"source": [ |
|
|
1240 |
"et.fit(train_df[feature],train_df['target'])" |
|
|
1241 |
] |
|
|
1242 |
}, |
|
|
1243 |
{ |
|
|
1244 |
"cell_type": "code", |
|
|
1245 |
"execution_count": null, |
|
|
1246 |
"metadata": {}, |
|
|
1247 |
"outputs": [], |
|
|
1248 |
"source": [ |
|
|
1249 |
"%%time \n", |
|
|
1250 |
"y_pred=et.predict(test_df[feature])" |
|
|
1251 |
] |
|
|
1252 |
}, |
|
|
1253 |
{ |
|
|
1254 |
"cell_type": "code", |
|
|
1255 |
"execution_count": null, |
|
|
1256 |
"metadata": {}, |
|
|
1257 |
"outputs": [], |
|
|
1258 |
"source": [ |
|
|
1259 |
"print(classification_report(test_df['target'], y_pred))" |
|
|
1260 |
] |
|
|
1261 |
}, |
|
|
1262 |
{ |
|
|
1263 |
"cell_type": "code", |
|
|
1264 |
"execution_count": null, |
|
|
1265 |
"metadata": {}, |
|
|
1266 |
"outputs": [], |
|
|
1267 |
"source": [ |
|
|
1268 |
"clf = KNeighborsClassifier(n_neighbors=1)\n", |
|
|
1269 |
"clf.fit(train_df[feature],train_df['target'])\n", |
|
|
1270 |
"y_pred=clf.predict(test_df[feature])" |
|
|
1271 |
] |
|
|
1272 |
}, |
|
|
1273 |
{ |
|
|
1274 |
"cell_type": "code", |
|
|
1275 |
"execution_count": null, |
|
|
1276 |
"metadata": {}, |
|
|
1277 |
"outputs": [], |
|
|
1278 |
"source": [ |
|
|
1279 |
"print(classification_report(test_df['target'], y_pred))" |
|
|
1280 |
] |
|
|
1281 |
}, |
|
|
1282 |
{ |
|
|
1283 |
"cell_type": "code", |
|
|
1284 |
"execution_count": null, |
|
|
1285 |
"metadata": {}, |
|
|
1286 |
"outputs": [], |
|
|
1287 |
"source": [] |
|
|
1288 |
} |
|
|
1289 |
], |
|
|
1290 |
"metadata": { |
|
|
1291 |
"kernelspec": { |
|
|
1292 |
"display_name": "Python 3", |
|
|
1293 |
"language": "python", |
|
|
1294 |
"name": "python3" |
|
|
1295 |
}, |
|
|
1296 |
"language_info": { |
|
|
1297 |
"codemirror_mode": { |
|
|
1298 |
"name": "ipython", |
|
|
1299 |
"version": 3 |
|
|
1300 |
}, |
|
|
1301 |
"file_extension": ".py", |
|
|
1302 |
"mimetype": "text/x-python", |
|
|
1303 |
"name": "python", |
|
|
1304 |
"nbconvert_exporter": "python", |
|
|
1305 |
"pygments_lexer": "ipython3", |
|
|
1306 |
"version": "3.6.8" |
|
|
1307 |
} |
|
|
1308 |
}, |
|
|
1309 |
"nbformat": 4, |
|
|
1310 |
"nbformat_minor": 2 |
|
|
1311 |
} |