|
a |
|
b/TCARER_summaryReports.ipynb |
|
|
1 |
{ |
|
|
2 |
"cells": [ |
|
|
3 |
{ |
|
|
4 |
"cell_type": "markdown", |
|
|
5 |
"metadata": { |
|
|
6 |
"deletable": true, |
|
|
7 |
"editable": true |
|
|
8 |
}, |
|
|
9 |
"source": [ |
|
|
10 |
"# Temporal-Comorbidity Adjusted Risk of Emergency Readmission (TCARER)\n", |
|
|
11 |
"## <font style=\"font-weight:bold;color:gray\">Summary Reports</font>" |
|
|
12 |
] |
|
|
13 |
}, |
|
|
14 |
{ |
|
|
15 |
"cell_type": "markdown", |
|
|
16 |
"metadata": { |
|
|
17 |
"deletable": true, |
|
|
18 |
"editable": true |
|
|
19 |
}, |
|
|
20 |
"source": [ |
|
|
21 |
"## 1. Initialise" |
|
|
22 |
] |
|
|
23 |
}, |
|
|
24 |
{ |
|
|
25 |
"cell_type": "code", |
|
|
26 |
"execution_count": 1, |
|
|
27 |
"metadata": { |
|
|
28 |
"collapsed": false, |
|
|
29 |
"deletable": true, |
|
|
30 |
"editable": true, |
|
|
31 |
"scrolled": true |
|
|
32 |
}, |
|
|
33 |
"outputs": [], |
|
|
34 |
"source": [ |
|
|
35 |
"# reload modules\n", |
|
|
36 |
"# Reload all modules (except those excluded by %aimport) every time before executing the Python code typed.\n", |
|
|
37 |
"%load_ext autoreload \n", |
|
|
38 |
"%autoreload 2" |
|
|
39 |
] |
|
|
40 |
}, |
|
|
41 |
{ |
|
|
42 |
"cell_type": "code", |
|
|
43 |
"execution_count": 2, |
|
|
44 |
"metadata": { |
|
|
45 |
"collapsed": false, |
|
|
46 |
"deletable": true, |
|
|
47 |
"editable": true |
|
|
48 |
}, |
|
|
49 |
"outputs": [], |
|
|
50 |
"source": [ |
|
|
51 |
"# import libraries\n", |
|
|
52 |
"import logging\n", |
|
|
53 |
"import os\n", |
|
|
54 |
"import sys\n", |
|
|
55 |
"import gc\n", |
|
|
56 |
"import pandas as pd\n", |
|
|
57 |
"import numpy as np\n", |
|
|
58 |
"import random\n", |
|
|
59 |
"import statistics\n", |
|
|
60 |
"from datetime import datetime\n", |
|
|
61 |
"from collections import OrderedDict\n", |
|
|
62 |
"from sklearn import preprocessing\n", |
|
|
63 |
"from scipy.stats import stats\n", |
|
|
64 |
"from IPython.display import display, HTML\n", |
|
|
65 |
"from pprint import pprint\n", |
|
|
66 |
"from pivottablejs import pivot_ui\n", |
|
|
67 |
"from IPython.display import clear_output\n", |
|
|
68 |
"import imblearn.over_sampling as oversampling\n", |
|
|
69 |
"import matplotlib.pyplot as plt" |
|
|
70 |
] |
|
|
71 |
}, |
|
|
72 |
{ |
|
|
73 |
"cell_type": "code", |
|
|
74 |
"execution_count": 4, |
|
|
75 |
"metadata": { |
|
|
76 |
"collapsed": false, |
|
|
77 |
"deletable": true, |
|
|
78 |
"editable": true |
|
|
79 |
}, |
|
|
80 |
"outputs": [], |
|
|
81 |
"source": [ |
|
|
82 |
"# import local classes\n", |
|
|
83 |
"from Configs.CONSTANTS import CONSTANTS\n", |
|
|
84 |
"from Configs.Logger import Logger\n", |
|
|
85 |
"from Features.Variables import Variables\n", |
|
|
86 |
"from ReadersWriters.ReadersWriters import ReadersWriters\n", |
|
|
87 |
"from Stats.PreProcess import PreProcess\n", |
|
|
88 |
"from Stats.FeatureSelection import FeatureSelection\n", |
|
|
89 |
"from Stats.TrainingMethod import TrainingMethod\n", |
|
|
90 |
"from Stats.Plots import Plots\n", |
|
|
91 |
"from Stats.Stats import Stats" |
|
|
92 |
] |
|
|
93 |
}, |
|
|
94 |
{ |
|
|
95 |
"cell_type": "code", |
|
|
96 |
"execution_count": 5, |
|
|
97 |
"metadata": { |
|
|
98 |
"collapsed": false, |
|
|
99 |
"deletable": true, |
|
|
100 |
"editable": true, |
|
|
101 |
"scrolled": true |
|
|
102 |
}, |
|
|
103 |
"outputs": [ |
|
|
104 |
{ |
|
|
105 |
"name": "stdout", |
|
|
106 |
"output_type": "stream", |
|
|
107 |
"text": [ |
|
|
108 |
"\n", |
|
|
109 |
"Make sure the correct Python interpreter is used!\n", |
|
|
110 |
"3.5.3 (v3.5.3:1880cb95a742, Jan 16 2017, 16:02:32) [MSC v.1900 64 bit (AMD64)]\n", |
|
|
111 |
"\n", |
|
|
112 |
"Make sure sys.path of the Python interpreter is correct!\n", |
|
|
113 |
"C:\\Users\\eagle\\Documents\\GitHub\\Analytics_UoW\\TCARER\n" |
|
|
114 |
] |
|
|
115 |
} |
|
|
116 |
], |
|
|
117 |
"source": [ |
|
|
118 |
"# Check the interpreter\n", |
|
|
119 |
"print(\"\\nMake sure the correct Python interpreter is used!\")\n", |
|
|
120 |
"print(sys.version)\n", |
|
|
121 |
"print(\"\\nMake sure sys.path of the Python interpreter is correct!\")\n", |
|
|
122 |
"print(os.getcwd())" |
|
|
123 |
] |
|
|
124 |
}, |
|
|
125 |
{ |
|
|
126 |
"cell_type": "markdown", |
|
|
127 |
"metadata": { |
|
|
128 |
"deletable": true, |
|
|
129 |
"editable": true |
|
|
130 |
}, |
|
|
131 |
"source": [ |
|
|
132 |
"### 1.1. Initialise General Settings" |
|
|
133 |
] |
|
|
134 |
}, |
|
|
135 |
{ |
|
|
136 |
"cell_type": "code", |
|
|
137 |
"execution_count": 6, |
|
|
138 |
"metadata": { |
|
|
139 |
"collapsed": false, |
|
|
140 |
"deletable": true, |
|
|
141 |
"editable": true |
|
|
142 |
}, |
|
|
143 |
"outputs": [ |
|
|
144 |
{ |
|
|
145 |
"name": "stdout", |
|
|
146 |
"output_type": "stream", |
|
|
147 |
"text": [ |
|
|
148 |
"Output path: C:\\Users\\eagle\\Documents\\GitHub\\tmp\\TCARER\\Basic_prototype\n" |
|
|
149 |
] |
|
|
150 |
} |
|
|
151 |
], |
|
|
152 |
"source": [ |
|
|
153 |
"# init paths & directories\n", |
|
|
154 |
"config_path = os.path.abspath(\"ConfigInputs/CONFIGURATIONS.ini\")\n", |
|
|
155 |
"io_path = os.path.abspath(\"../../tmp/TCARER/Basic_prototype\")\n", |
|
|
156 |
"schema = \"parr_sample_prototype\" \n", |
|
|
157 |
"app_name = \"T-CARER\"\n", |
|
|
158 |
"\n", |
|
|
159 |
"print(\"Output path:\", io_path)" |
|
|
160 |
] |
|
|
161 |
}, |
|
|
162 |
{ |
|
|
163 |
"cell_type": "code", |
|
|
164 |
"execution_count": 7, |
|
|
165 |
"metadata": { |
|
|
166 |
"collapsed": false, |
|
|
167 |
"deletable": true, |
|
|
168 |
"editable": true |
|
|
169 |
}, |
|
|
170 |
"outputs": [ |
|
|
171 |
{ |
|
|
172 |
"name": "stderr", |
|
|
173 |
"output_type": "stream", |
|
|
174 |
"text": [ |
|
|
175 |
"2017-10-29 13:03:26,935 - T-CARER - INFO - Creating 'C:\\Users\\eagle\\Documents\\GitHub\\tmp\\TCARER\\Basic_prototype\\T-CARER.log' File.\n" |
|
|
176 |
] |
|
|
177 |
} |
|
|
178 |
], |
|
|
179 |
"source": [ |
|
|
180 |
"# init logs\n", |
|
|
181 |
"if not os.path.exists(io_path):\n", |
|
|
182 |
" os.makedirs(io_path, exist_ok=True)\n", |
|
|
183 |
"\n", |
|
|
184 |
"logger = Logger(path=io_path, app_name=app_name, ext=\"log\")\n", |
|
|
185 |
"logger = logging.getLogger(app_name)" |
|
|
186 |
] |
|
|
187 |
}, |
|
|
188 |
{ |
|
|
189 |
"cell_type": "code", |
|
|
190 |
"execution_count": 8, |
|
|
191 |
"metadata": { |
|
|
192 |
"collapsed": false, |
|
|
193 |
"deletable": true, |
|
|
194 |
"editable": true |
|
|
195 |
}, |
|
|
196 |
"outputs": [], |
|
|
197 |
"source": [ |
|
|
198 |
"# init constants \n", |
|
|
199 |
"CONSTANTS.set(io_path, app_name)" |
|
|
200 |
] |
|
|
201 |
}, |
|
|
202 |
{ |
|
|
203 |
"cell_type": "code", |
|
|
204 |
"execution_count": 9, |
|
|
205 |
"metadata": { |
|
|
206 |
"collapsed": false, |
|
|
207 |
"deletable": true, |
|
|
208 |
"editable": true |
|
|
209 |
}, |
|
|
210 |
"outputs": [], |
|
|
211 |
"source": [ |
|
|
212 |
"# initialise other classes\n", |
|
|
213 |
"readers_writers = ReadersWriters()\n", |
|
|
214 |
"plots = Plots()" |
|
|
215 |
] |
|
|
216 |
}, |
|
|
217 |
{ |
|
|
218 |
"cell_type": "code", |
|
|
219 |
"execution_count": 10, |
|
|
220 |
"metadata": { |
|
|
221 |
"collapsed": true, |
|
|
222 |
"deletable": true, |
|
|
223 |
"editable": true |
|
|
224 |
}, |
|
|
225 |
"outputs": [], |
|
|
226 |
"source": [ |
|
|
227 |
"# other Constant variables\n", |
|
|
228 |
"submodel_name = \"hesIp\"\n", |
|
|
229 |
"submodel_input_name = \"tcarer_model_features_ip\"" |
|
|
230 |
] |
|
|
231 |
}, |
|
|
232 |
{ |
|
|
233 |
"cell_type": "code", |
|
|
234 |
"execution_count": 11, |
|
|
235 |
"metadata": { |
|
|
236 |
"collapsed": true, |
|
|
237 |
"deletable": true, |
|
|
238 |
"editable": true |
|
|
239 |
}, |
|
|
240 |
"outputs": [], |
|
|
241 |
"source": [ |
|
|
242 |
"# set print settings\n", |
|
|
243 |
"pd.set_option('display.width', 1600, 'display.max_colwidth', 800)" |
|
|
244 |
] |
|
|
245 |
}, |
|
|
246 |
{ |
|
|
247 |
"cell_type": "markdown", |
|
|
248 |
"metadata": { |
|
|
249 |
"deletable": true, |
|
|
250 |
"editable": true |
|
|
251 |
}, |
|
|
252 |
"source": [ |
|
|
253 |
" Common variables:\n", |
|
|
254 |
"* Readmission\n", |
|
|
255 |
" * 'label30', 'label365'\n", |
|
|
256 |
"* Admissions Methods:\n", |
|
|
257 |
" * 'admimeth\\_0t30d\\_prevalence\\_1\\_cnt', ...\n", |
|
|
258 |
"* Prior Spells: \n", |
|
|
259 |
" * 'prior\\_spells'\n", |
|
|
260 |
"* Male:\n", |
|
|
261 |
" * 'gender\\_1'\n", |
|
|
262 |
"* LoS:\n", |
|
|
263 |
" * 'trigger\\_los'\n", |
|
|
264 |
"* Age:\n", |
|
|
265 |
" * 'trigger\\_age'\n", |
|
|
266 |
"* Charlson Score:\n", |
|
|
267 |
" * 'trigger\\_charlsonFoster'\n", |
|
|
268 |
"* predictions score\n", |
|
|
269 |
" * score\n", |
|
|
270 |
"* Most prevalent diagnoses groups (0-30-day, 0-730-day):\n", |
|
|
271 |
" * 0-30-day: 'diagCCS\\_0t30d\\_prevalence\\_1\\_cnt', ...\n", |
|
|
272 |
" * 0-730-day: 'diagCCS\\_0t30d\\_prevalence\\_1\\_cnt' + 'diagCCS\\_30t90d\\_prevalence\\_1\\_cnt' + \n", |
|
|
273 |
" 'diagCCS\\_90t180d\\_prevalence\\_1\\_cnt' + 'diagCCS\\_180t365d\\_prevalence\\_1\\_cnt' + \n", |
|
|
274 |
" 'diagCCS\\_365t730d\\_prevalence\\_1\\_cnt', ...\n", |
|
|
275 |
"* Comorbidity diagnoses groups (0-730-day):\n", |
|
|
276 |
" * 'prior\\_admiOther', 'prior\\_admiAcute', 'prior\\_spells', 'prior\\_asthma', 'prior\\_copd', 'prior\\_depression', 'prior\\_diabetes', 'prior\\_hypertension', 'prior\\_cancer', 'prior\\_chd', 'prior\\_chf'\n", |
|
|
277 |
"* Charlson diagnoses groups (trigger):\n", |
|
|
278 |
" * 'diagCci\\_01\\_myocardial\\_freq\\_\\_trigger',..." |
|
|
279 |
] |
|
|
280 |
}, |
|
|
281 |
{ |
|
|
282 |
"cell_type": "markdown", |
|
|
283 |
"metadata": { |
|
|
284 |
"deletable": true, |
|
|
285 |
"editable": true |
|
|
286 |
}, |
|
|
287 |
"source": [ |
|
|
288 |
"<br/><br/>" |
|
|
289 |
] |
|
|
290 |
}, |
|
|
291 |
{ |
|
|
292 |
"cell_type": "markdown", |
|
|
293 |
"metadata": { |
|
|
294 |
"deletable": true, |
|
|
295 |
"editable": true |
|
|
296 |
}, |
|
|
297 |
"source": [ |
|
|
298 |
"## 2. Load the Saved Model Outputs" |
|
|
299 |
] |
|
|
300 |
}, |
|
|
301 |
{ |
|
|
302 |
"cell_type": "markdown", |
|
|
303 |
"metadata": { |
|
|
304 |
"deletable": true, |
|
|
305 |
"editable": true |
|
|
306 |
}, |
|
|
307 |
"source": [ |
|
|
308 |
"<font style=\"font-weight:bold;color:red\">Note: Make sure the following files are located at the input path</font>\n", |
|
|
309 |
"* Step\\_05\\_Features.bz2\n", |
|
|
310 |
"* Step\\_07\\_Top\\_Features\\_...\n", |
|
|
311 |
"* Step\\_07\\_Model\\_Train\\_model\\_rank\\_summaries\\_...\n", |
|
|
312 |
"* Step\\_09\\_Model\\_..." |
|
|
313 |
] |
|
|
314 |
}, |
|
|
315 |
{ |
|
|
316 |
"cell_type": "markdown", |
|
|
317 |
"metadata": { |
|
|
318 |
"deletable": true, |
|
|
319 |
"editable": true |
|
|
320 |
}, |
|
|
321 |
"source": [ |
|
|
322 |
"<font style=\"font-weight:bold;color:red\">Note: Create features extra (Run only once)</font>" |
|
|
323 |
] |
|
|
324 |
}, |
|
|
325 |
{ |
|
|
326 |
"cell_type": "code", |
|
|
327 |
"execution_count": null, |
|
|
328 |
"metadata": { |
|
|
329 |
"collapsed": true, |
|
|
330 |
"deletable": true, |
|
|
331 |
"editable": true |
|
|
332 |
}, |
|
|
333 |
"outputs": [], |
|
|
334 |
"source": [ |
|
|
335 |
"# settings\n", |
|
|
336 |
"feature_table = 'tcarer_features'\n", |
|
|
337 |
"featureExtra_table = 'tcarer_featuresExtra'" |
|
|
338 |
] |
|
|
339 |
}, |
|
|
340 |
{ |
|
|
341 |
"cell_type": "code", |
|
|
342 |
"execution_count": null, |
|
|
343 |
"metadata": { |
|
|
344 |
"collapsed": false, |
|
|
345 |
"deletable": true, |
|
|
346 |
"editable": true, |
|
|
347 |
"scrolled": true |
|
|
348 |
}, |
|
|
349 |
"outputs": [], |
|
|
350 |
"source": [ |
|
|
351 |
"result = readers_writers.load_mysql_procedure(\"tcarer_set_featuresExtra\", [feature_table, featureExtra_table], schema)" |
|
|
352 |
] |
|
|
353 |
}, |
|
|
354 |
{ |
|
|
355 |
"cell_type": "markdown", |
|
|
356 |
"metadata": { |
|
|
357 |
"deletable": true, |
|
|
358 |
"editable": true |
|
|
359 |
}, |
|
|
360 |
"source": [ |
|
|
361 |
"<br/><br/>" |
|
|
362 |
] |
|
|
363 |
}, |
|
|
364 |
{ |
|
|
365 |
"cell_type": "markdown", |
|
|
366 |
"metadata": { |
|
|
367 |
"deletable": true, |
|
|
368 |
"editable": true |
|
|
369 |
}, |
|
|
370 |
"source": [ |
|
|
371 |
"### 2.1. Initialise" |
|
|
372 |
] |
|
|
373 |
}, |
|
|
374 |
{ |
|
|
375 |
"cell_type": "code", |
|
|
376 |
"execution_count": 16, |
|
|
377 |
"metadata": { |
|
|
378 |
"collapsed": true, |
|
|
379 |
"deletable": true, |
|
|
380 |
"editable": true |
|
|
381 |
}, |
|
|
382 |
"outputs": [], |
|
|
383 |
"source": [ |
|
|
384 |
"# select the target variable\n", |
|
|
385 |
"target_feature = \"label365\" # \"label365\", \"label30\" \n", |
|
|
386 |
"method_name = \"rfc\" # \"rfc\", \"gbrt\", \"randLogit\", \"wdnn\"\n", |
|
|
387 |
"rank_models = [\"rfc\"] # [\"rfc\", \"gbrt\", \"randLogit\"]" |
|
|
388 |
] |
|
|
389 |
}, |
|
|
390 |
{ |
|
|
391 |
"cell_type": "markdown", |
|
|
392 |
"metadata": { |
|
|
393 |
"deletable": true, |
|
|
394 |
"editable": true |
|
|
395 |
}, |
|
|
396 |
"source": [ |
|
|
397 |
"<br/><br/>" |
|
|
398 |
] |
|
|
399 |
}, |
|
|
400 |
{ |
|
|
401 |
"cell_type": "markdown", |
|
|
402 |
"metadata": { |
|
|
403 |
"collapsed": true, |
|
|
404 |
"deletable": true, |
|
|
405 |
"editable": true |
|
|
406 |
}, |
|
|
407 |
"source": [ |
|
|
408 |
"### 2.2. Load Features" |
|
|
409 |
] |
|
|
410 |
}, |
|
|
411 |
{ |
|
|
412 |
"cell_type": "markdown", |
|
|
413 |
"metadata": { |
|
|
414 |
"deletable": true, |
|
|
415 |
"editable": true |
|
|
416 |
}, |
|
|
417 |
"source": [ |
|
|
418 |
"Load pre-processed features" |
|
|
419 |
] |
|
|
420 |
}, |
|
|
421 |
{ |
|
|
422 |
"cell_type": "code", |
|
|
423 |
"execution_count": 17, |
|
|
424 |
"metadata": { |
|
|
425 |
"collapsed": false, |
|
|
426 |
"deletable": true, |
|
|
427 |
"editable": true |
|
|
428 |
}, |
|
|
429 |
"outputs": [ |
|
|
430 |
{ |
|
|
431 |
"name": "stdout", |
|
|
432 |
"output_type": "stream", |
|
|
433 |
"text": [ |
|
|
434 |
"File size: 97692\n", |
|
|
435 |
"Number of columns: 458\n", |
|
|
436 |
"features: {train: 2500 , test: 2499 }\n" |
|
|
437 |
] |
|
|
438 |
} |
|
|
439 |
], |
|
|
440 |
"source": [ |
|
|
441 |
"file_name = \"Step_07_Features\"\n", |
|
|
442 |
"features = readers_writers.load_serialised_compressed(path=CONSTANTS.io_path, title=file_name)\n", |
|
|
443 |
"\n", |
|
|
444 |
"# print \n", |
|
|
445 |
"print(\"File size: \", os.stat(os.path.join(CONSTANTS.io_path, file_name + \".bz2\")).st_size)\n", |
|
|
446 |
"print(\"Number of columns: \", len(features[\"train_indep\"].columns)) \n", |
|
|
447 |
"print(\"features: {train: \", len(features[\"train_indep\"]), \", test: \", len(features[\"test_indep\"]), \"}\")" |
|
|
448 |
] |
|
|
449 |
}, |
|
|
450 |
{ |
|
|
451 |
"cell_type": "markdown", |
|
|
452 |
"metadata": { |
|
|
453 |
"deletable": true, |
|
|
454 |
"editable": true |
|
|
455 |
}, |
|
|
456 |
"source": [ |
|
|
457 |
"### 2.3. Load Features Names" |
|
|
458 |
] |
|
|
459 |
}, |
|
|
460 |
{ |
|
|
461 |
"cell_type": "code", |
|
|
462 |
"execution_count": 18, |
|
|
463 |
"metadata": { |
|
|
464 |
"collapsed": false, |
|
|
465 |
"deletable": true, |
|
|
466 |
"editable": true |
|
|
467 |
}, |
|
|
468 |
"outputs": [ |
|
|
469 |
{ |
|
|
470 |
"data": { |
|
|
471 |
"text/html": [ |
|
|
472 |
"<div>\n", |
|
|
473 |
"<table border=\"1\" class=\"dataframe\">\n", |
|
|
474 |
" <thead>\n", |
|
|
475 |
" <tr style=\"text-align: right;\">\n", |
|
|
476 |
" <th></th>\n", |
|
|
477 |
" <th>0</th>\n", |
|
|
478 |
" </tr>\n", |
|
|
479 |
" </thead>\n", |
|
|
480 |
" <tbody>\n", |
|
|
481 |
" <tr>\n", |
|
|
482 |
" <th>0</th>\n", |
|
|
483 |
" <td>epidur_0t30d_avg</td>\n", |
|
|
484 |
" </tr>\n", |
|
|
485 |
" <tr>\n", |
|
|
486 |
" <th>1</th>\n", |
|
|
487 |
" <td>epidur_365t730d_avg</td>\n", |
|
|
488 |
" </tr>\n", |
|
|
489 |
" <tr>\n", |
|
|
490 |
" <th>2</th>\n", |
|
|
491 |
" <td>preopdur_0t30d_avg</td>\n", |
|
|
492 |
" </tr>\n", |
|
|
493 |
" <tr>\n", |
|
|
494 |
" <th>3</th>\n", |
|
|
495 |
" <td>gapDays_0t30d_others_cnt</td>\n", |
|
|
496 |
" </tr>\n", |
|
|
497 |
" <tr>\n", |
|
|
498 |
" <th>4</th>\n", |
|
|
499 |
" <td>epidur_365t730d_others_cnt</td>\n", |
|
|
500 |
" </tr>\n", |
|
|
501 |
" <tr>\n", |
|
|
502 |
" <th>5</th>\n", |
|
|
503 |
" <td>preopdur_30t90d_others_cnt</td>\n", |
|
|
504 |
" </tr>\n", |
|
|
505 |
" <tr>\n", |
|
|
506 |
" <th>6</th>\n", |
|
|
507 |
" <td>epidur_0t30d_others_cnt</td>\n", |
|
|
508 |
" </tr>\n", |
|
|
509 |
" <tr>\n", |
|
|
510 |
" <th>7</th>\n", |
|
|
511 |
" <td>preopdur_0t30d_others_cnt</td>\n", |
|
|
512 |
" </tr>\n", |
|
|
513 |
" <tr>\n", |
|
|
514 |
" <th>8</th>\n", |
|
|
515 |
" <td>epidur_30t90d_others_cnt</td>\n", |
|
|
516 |
" </tr>\n", |
|
|
517 |
" <tr>\n", |
|
|
518 |
" <th>9</th>\n", |
|
|
519 |
" <td>preopdur_90t180d_others_cnt</td>\n", |
|
|
520 |
" </tr>\n", |
|
|
521 |
" <tr>\n", |
|
|
522 |
" <th>10</th>\n", |
|
|
523 |
" <td>epidur_180t365d_avg</td>\n", |
|
|
524 |
" </tr>\n", |
|
|
525 |
" <tr>\n", |
|
|
526 |
" <th>11</th>\n", |
|
|
527 |
" <td>preopdur_30t90d_avg</td>\n", |
|
|
528 |
" </tr>\n", |
|
|
529 |
" <tr>\n", |
|
|
530 |
" <th>12</th>\n", |
|
|
531 |
" <td>preopdur_90t180d_avg</td>\n", |
|
|
532 |
" </tr>\n", |
|
|
533 |
" <tr>\n", |
|
|
534 |
" <th>13</th>\n", |
|
|
535 |
" <td>gapDays_365t730d_avg</td>\n", |
|
|
536 |
" </tr>\n", |
|
|
537 |
" <tr>\n", |
|
|
538 |
" <th>14</th>\n", |
|
|
539 |
" <td>operOPCSL1_0t30d_prevalence_1_cnt</td>\n", |
|
|
540 |
" </tr>\n", |
|
|
541 |
" <tr>\n", |
|
|
542 |
" <th>15</th>\n", |
|
|
543 |
" <td>operOPCSL1_0t30d_others_cnt</td>\n", |
|
|
544 |
" </tr>\n", |
|
|
545 |
" <tr>\n", |
|
|
546 |
" <th>16</th>\n", |
|
|
547 |
" <td>posopdur_30t90d_others_cnt</td>\n", |
|
|
548 |
" </tr>\n", |
|
|
549 |
" <tr>\n", |
|
|
550 |
" <th>17</th>\n", |
|
|
551 |
" <td>epidur_180t365d_others_cnt</td>\n", |
|
|
552 |
" </tr>\n", |
|
|
553 |
" <tr>\n", |
|
|
554 |
" <th>18</th>\n", |
|
|
555 |
" <td>posopdur_0t30d_avg</td>\n", |
|
|
556 |
" </tr>\n", |
|
|
557 |
" <tr>\n", |
|
|
558 |
" <th>19</th>\n", |
|
|
559 |
" <td>preopdur_180t365d_others_cnt</td>\n", |
|
|
560 |
" </tr>\n", |
|
|
561 |
" <tr>\n", |
|
|
562 |
" <th>20</th>\n", |
|
|
563 |
" <td>operOPCSL1_0t30d_prevalence_3_cnt</td>\n", |
|
|
564 |
" </tr>\n", |
|
|
565 |
" <tr>\n", |
|
|
566 |
" <th>21</th>\n", |
|
|
567 |
" <td>operOPCSL1_0t30d_prevalence_4_cnt</td>\n", |
|
|
568 |
" </tr>\n", |
|
|
569 |
" <tr>\n", |
|
|
570 |
" <th>22</th>\n", |
|
|
571 |
" <td>posopdur_365t730d_avg</td>\n", |
|
|
572 |
" </tr>\n", |
|
|
573 |
" <tr>\n", |
|
|
574 |
" <th>23</th>\n", |
|
|
575 |
" <td>operOPCSL1_0t30d_prevalence_2_cnt</td>\n", |
|
|
576 |
" </tr>\n", |
|
|
577 |
" <tr>\n", |
|
|
578 |
" <th>24</th>\n", |
|
|
579 |
" <td>epidur_30t90d_avg</td>\n", |
|
|
580 |
" </tr>\n", |
|
|
581 |
" <tr>\n", |
|
|
582 |
" <th>25</th>\n", |
|
|
583 |
" <td>posopdur_30t90d_avg</td>\n", |
|
|
584 |
" </tr>\n", |
|
|
585 |
" <tr>\n", |
|
|
586 |
" <th>26</th>\n", |
|
|
587 |
" <td>operOPCSL1_0t30d_prevalence_5_cnt</td>\n", |
|
|
588 |
" </tr>\n", |
|
|
589 |
" <tr>\n", |
|
|
590 |
" <th>27</th>\n", |
|
|
591 |
" <td>preopdur_180t365d_avg</td>\n", |
|
|
592 |
" </tr>\n", |
|
|
593 |
" <tr>\n", |
|
|
594 |
" <th>28</th>\n", |
|
|
595 |
" <td>preopdur_365t730d_others_cnt</td>\n", |
|
|
596 |
" </tr>\n", |
|
|
597 |
" <tr>\n", |
|
|
598 |
" <th>29</th>\n", |
|
|
599 |
" <td>preopdur_365t730d_avg</td>\n", |
|
|
600 |
" </tr>\n", |
|
|
601 |
" <tr>\n", |
|
|
602 |
" <th>...</th>\n", |
|
|
603 |
" <td>...</td>\n", |
|
|
604 |
" </tr>\n", |
|
|
605 |
" <tr>\n", |
|
|
606 |
" <th>370</th>\n", |
|
|
607 |
" <td>operOPCSL1_180t365d_prevalence_30_cnt</td>\n", |
|
|
608 |
" </tr>\n", |
|
|
609 |
" <tr>\n", |
|
|
610 |
" <th>371</th>\n", |
|
|
611 |
" <td>diagCCS_0t30d_prevalence_25_cnt</td>\n", |
|
|
612 |
" </tr>\n", |
|
|
613 |
" <tr>\n", |
|
|
614 |
" <th>372</th>\n", |
|
|
615 |
" <td>diagCCS_30t90d_prevalence_1_cnt</td>\n", |
|
|
616 |
" </tr>\n", |
|
|
617 |
" <tr>\n", |
|
|
618 |
" <th>373</th>\n", |
|
|
619 |
" <td>diagCCS_0t30d_prevalence_23_cnt</td>\n", |
|
|
620 |
" </tr>\n", |
|
|
621 |
" <tr>\n", |
|
|
622 |
" <th>374</th>\n", |
|
|
623 |
" <td>diagCCS_90t180d_prevalence_5_cnt</td>\n", |
|
|
624 |
" </tr>\n", |
|
|
625 |
" <tr>\n", |
|
|
626 |
" <th>375</th>\n", |
|
|
627 |
" <td>diagCCS_90t180d_prevalence_4_cnt</td>\n", |
|
|
628 |
" </tr>\n", |
|
|
629 |
" <tr>\n", |
|
|
630 |
" <th>376</th>\n", |
|
|
631 |
" <td>diagCCS_0t30d_prevalence_19_cnt</td>\n", |
|
|
632 |
" </tr>\n", |
|
|
633 |
" <tr>\n", |
|
|
634 |
" <th>377</th>\n", |
|
|
635 |
" <td>operOPCSL1_365t730d_prevalence_4_cnt</td>\n", |
|
|
636 |
" </tr>\n", |
|
|
637 |
" <tr>\n", |
|
|
638 |
" <th>378</th>\n", |
|
|
639 |
" <td>diagCCS_90t180d_prevalence_2_cnt</td>\n", |
|
|
640 |
" </tr>\n", |
|
|
641 |
" <tr>\n", |
|
|
642 |
" <th>379</th>\n", |
|
|
643 |
" <td>diagCCS_90t180d_prevalence_3_cnt</td>\n", |
|
|
644 |
" </tr>\n", |
|
|
645 |
" <tr>\n", |
|
|
646 |
" <th>380</th>\n", |
|
|
647 |
" <td>diagCCS_0t30d_prevalence_21_cnt</td>\n", |
|
|
648 |
" </tr>\n", |
|
|
649 |
" <tr>\n", |
|
|
650 |
" <th>381</th>\n", |
|
|
651 |
" <td>diagCCS_30t90d_prevalence_3_cnt</td>\n", |
|
|
652 |
" </tr>\n", |
|
|
653 |
" <tr>\n", |
|
|
654 |
" <th>382</th>\n", |
|
|
655 |
" <td>diagCCS_30t90d_prevalence_4_cnt</td>\n", |
|
|
656 |
" </tr>\n", |
|
|
657 |
" <tr>\n", |
|
|
658 |
" <th>383</th>\n", |
|
|
659 |
" <td>diagCCS_30t90d_prevalence_2_cnt</td>\n", |
|
|
660 |
" </tr>\n", |
|
|
661 |
" <tr>\n", |
|
|
662 |
" <th>384</th>\n", |
|
|
663 |
" <td>operOPCSL1_365t730d_prevalence_5_cnt</td>\n", |
|
|
664 |
" </tr>\n", |
|
|
665 |
" <tr>\n", |
|
|
666 |
" <th>385</th>\n", |
|
|
667 |
" <td>diagCCS_30t90d_prevalence_5_cnt</td>\n", |
|
|
668 |
" </tr>\n", |
|
|
669 |
" <tr>\n", |
|
|
670 |
" <th>386</th>\n", |
|
|
671 |
" <td>diagCCS_0t30d_prevalence_20_cnt</td>\n", |
|
|
672 |
" </tr>\n", |
|
|
673 |
" <tr>\n", |
|
|
674 |
" <th>387</th>\n", |
|
|
675 |
" <td>diagCCS_30t90d_prevalence_6_cnt</td>\n", |
|
|
676 |
" </tr>\n", |
|
|
677 |
" <tr>\n", |
|
|
678 |
" <th>388</th>\n", |
|
|
679 |
" <td>diagCCS_30t90d_prevalence_7_cnt</td>\n", |
|
|
680 |
" </tr>\n", |
|
|
681 |
" <tr>\n", |
|
|
682 |
" <th>389</th>\n", |
|
|
683 |
" <td>diagCCS_30t90d_prevalence_8_cnt</td>\n", |
|
|
684 |
" </tr>\n", |
|
|
685 |
" <tr>\n", |
|
|
686 |
" <th>390</th>\n", |
|
|
687 |
" <td>operOPCSL1_365t730d_prevalence_6_cnt</td>\n", |
|
|
688 |
" </tr>\n", |
|
|
689 |
" <tr>\n", |
|
|
690 |
" <th>391</th>\n", |
|
|
691 |
" <td>diagCCS_90t180d_prevalence_1_cnt</td>\n", |
|
|
692 |
" </tr>\n", |
|
|
693 |
" <tr>\n", |
|
|
694 |
" <th>392</th>\n", |
|
|
695 |
" <td>diagCCS_90t180d_others_cnt</td>\n", |
|
|
696 |
" </tr>\n", |
|
|
697 |
" <tr>\n", |
|
|
698 |
" <th>393</th>\n", |
|
|
699 |
" <td>operOPCSL1_365t730d_prevalence_7_cnt</td>\n", |
|
|
700 |
" </tr>\n", |
|
|
701 |
" <tr>\n", |
|
|
702 |
" <th>394</th>\n", |
|
|
703 |
" <td>diagCCS_0t30d_prevalence_17_cnt</td>\n", |
|
|
704 |
" </tr>\n", |
|
|
705 |
" <tr>\n", |
|
|
706 |
" <th>395</th>\n", |
|
|
707 |
" <td>diagCCS_0t30d_prevalence_18_cnt</td>\n", |
|
|
708 |
" </tr>\n", |
|
|
709 |
" <tr>\n", |
|
|
710 |
" <th>396</th>\n", |
|
|
711 |
" <td>diagCCS_0t30d_prevalence_16_cnt</td>\n", |
|
|
712 |
" </tr>\n", |
|
|
713 |
" <tr>\n", |
|
|
714 |
" <th>397</th>\n", |
|
|
715 |
" <td>operOPCSL1_365t730d_prevalence_8_cnt</td>\n", |
|
|
716 |
" </tr>\n", |
|
|
717 |
" <tr>\n", |
|
|
718 |
" <th>398</th>\n", |
|
|
719 |
" <td>diagCCS_30t90d_prevalence_30_cnt</td>\n", |
|
|
720 |
" </tr>\n", |
|
|
721 |
" <tr>\n", |
|
|
722 |
" <th>399</th>\n", |
|
|
723 |
" <td>diagCCS_30t90d_prevalence_29_cnt</td>\n", |
|
|
724 |
" </tr>\n", |
|
|
725 |
" </tbody>\n", |
|
|
726 |
"</table>\n", |
|
|
727 |
"<p>400 rows × 1 columns</p>\n", |
|
|
728 |
"</div>" |
|
|
729 |
], |
|
|
730 |
"text/plain": [ |
|
|
731 |
" 0\n", |
|
|
732 |
"0 epidur_0t30d_avg\n", |
|
|
733 |
"1 epidur_365t730d_avg\n", |
|
|
734 |
"2 preopdur_0t30d_avg\n", |
|
|
735 |
"3 gapDays_0t30d_others_cnt\n", |
|
|
736 |
"4 epidur_365t730d_others_cnt\n", |
|
|
737 |
"5 preopdur_30t90d_others_cnt\n", |
|
|
738 |
"6 epidur_0t30d_others_cnt\n", |
|
|
739 |
"7 preopdur_0t30d_others_cnt\n", |
|
|
740 |
"8 epidur_30t90d_others_cnt\n", |
|
|
741 |
"9 preopdur_90t180d_others_cnt\n", |
|
|
742 |
"10 epidur_180t365d_avg\n", |
|
|
743 |
"11 preopdur_30t90d_avg\n", |
|
|
744 |
"12 preopdur_90t180d_avg\n", |
|
|
745 |
"13 gapDays_365t730d_avg\n", |
|
|
746 |
"14 operOPCSL1_0t30d_prevalence_1_cnt\n", |
|
|
747 |
"15 operOPCSL1_0t30d_others_cnt\n", |
|
|
748 |
"16 posopdur_30t90d_others_cnt\n", |
|
|
749 |
"17 epidur_180t365d_others_cnt\n", |
|
|
750 |
"18 posopdur_0t30d_avg\n", |
|
|
751 |
"19 preopdur_180t365d_others_cnt\n", |
|
|
752 |
"20 operOPCSL1_0t30d_prevalence_3_cnt\n", |
|
|
753 |
"21 operOPCSL1_0t30d_prevalence_4_cnt\n", |
|
|
754 |
"22 posopdur_365t730d_avg\n", |
|
|
755 |
"23 operOPCSL1_0t30d_prevalence_2_cnt\n", |
|
|
756 |
"24 epidur_30t90d_avg\n", |
|
|
757 |
"25 posopdur_30t90d_avg\n", |
|
|
758 |
"26 operOPCSL1_0t30d_prevalence_5_cnt\n", |
|
|
759 |
"27 preopdur_180t365d_avg\n", |
|
|
760 |
"28 preopdur_365t730d_others_cnt\n", |
|
|
761 |
"29 preopdur_365t730d_avg\n", |
|
|
762 |
".. ...\n", |
|
|
763 |
"370 operOPCSL1_180t365d_prevalence_30_cnt\n", |
|
|
764 |
"371 diagCCS_0t30d_prevalence_25_cnt\n", |
|
|
765 |
"372 diagCCS_30t90d_prevalence_1_cnt\n", |
|
|
766 |
"373 diagCCS_0t30d_prevalence_23_cnt\n", |
|
|
767 |
"374 diagCCS_90t180d_prevalence_5_cnt\n", |
|
|
768 |
"375 diagCCS_90t180d_prevalence_4_cnt\n", |
|
|
769 |
"376 diagCCS_0t30d_prevalence_19_cnt\n", |
|
|
770 |
"377 operOPCSL1_365t730d_prevalence_4_cnt\n", |
|
|
771 |
"378 diagCCS_90t180d_prevalence_2_cnt\n", |
|
|
772 |
"379 diagCCS_90t180d_prevalence_3_cnt\n", |
|
|
773 |
"380 diagCCS_0t30d_prevalence_21_cnt\n", |
|
|
774 |
"381 diagCCS_30t90d_prevalence_3_cnt\n", |
|
|
775 |
"382 diagCCS_30t90d_prevalence_4_cnt\n", |
|
|
776 |
"383 diagCCS_30t90d_prevalence_2_cnt\n", |
|
|
777 |
"384 operOPCSL1_365t730d_prevalence_5_cnt\n", |
|
|
778 |
"385 diagCCS_30t90d_prevalence_5_cnt\n", |
|
|
779 |
"386 diagCCS_0t30d_prevalence_20_cnt\n", |
|
|
780 |
"387 diagCCS_30t90d_prevalence_6_cnt\n", |
|
|
781 |
"388 diagCCS_30t90d_prevalence_7_cnt\n", |
|
|
782 |
"389 diagCCS_30t90d_prevalence_8_cnt\n", |
|
|
783 |
"390 operOPCSL1_365t730d_prevalence_6_cnt\n", |
|
|
784 |
"391 diagCCS_90t180d_prevalence_1_cnt\n", |
|
|
785 |
"392 diagCCS_90t180d_others_cnt\n", |
|
|
786 |
"393 operOPCSL1_365t730d_prevalence_7_cnt\n", |
|
|
787 |
"394 diagCCS_0t30d_prevalence_17_cnt\n", |
|
|
788 |
"395 diagCCS_0t30d_prevalence_18_cnt\n", |
|
|
789 |
"396 diagCCS_0t30d_prevalence_16_cnt\n", |
|
|
790 |
"397 operOPCSL1_365t730d_prevalence_8_cnt\n", |
|
|
791 |
"398 diagCCS_30t90d_prevalence_30_cnt\n", |
|
|
792 |
"399 diagCCS_30t90d_prevalence_29_cnt\n", |
|
|
793 |
"\n", |
|
|
794 |
"[400 rows x 1 columns]" |
|
|
795 |
] |
|
|
796 |
}, |
|
|
797 |
"metadata": {}, |
|
|
798 |
"output_type": "display_data" |
|
|
799 |
} |
|
|
800 |
], |
|
|
801 |
"source": [ |
|
|
802 |
"file_name = \"Step_07_Top_Features_rfc_adhoc\" \n", |
|
|
803 |
"\n", |
|
|
804 |
"features_names_selected = readers_writers.load_csv(path=CONSTANTS.io_path, title=file_name, dataframing=False)[0]\n", |
|
|
805 |
"features_names_selected = [f.replace(\"\\n\", \"\") for f in features_names_selected]\n", |
|
|
806 |
"display(pd.DataFrame(features_names_selected))" |
|
|
807 |
] |
|
|
808 |
}, |
|
|
809 |
{ |
|
|
810 |
"cell_type": "markdown", |
|
|
811 |
"metadata": { |
|
|
812 |
"deletable": true, |
|
|
813 |
"editable": true |
|
|
814 |
}, |
|
|
815 |
"source": [ |
|
|
816 |
"### 2.4. Load the fitted model" |
|
|
817 |
] |
|
|
818 |
}, |
|
|
819 |
{ |
|
|
820 |
"cell_type": "markdown", |
|
|
821 |
"metadata": { |
|
|
822 |
"deletable": true, |
|
|
823 |
"editable": true |
|
|
824 |
}, |
|
|
825 |
"source": [ |
|
|
826 |
"#### <font style=\"font-weight:bold;color:blue\">2.4.1. Basic Models</font>" |
|
|
827 |
] |
|
|
828 |
}, |
|
|
829 |
{ |
|
|
830 |
"cell_type": "markdown", |
|
|
831 |
"metadata": { |
|
|
832 |
"deletable": true, |
|
|
833 |
"editable": true |
|
|
834 |
}, |
|
|
835 |
"source": [ |
|
|
836 |
"Initialise" |
|
|
837 |
] |
|
|
838 |
}, |
|
|
839 |
{ |
|
|
840 |
"cell_type": "code", |
|
|
841 |
"execution_count": 19, |
|
|
842 |
"metadata": { |
|
|
843 |
"collapsed": false, |
|
|
844 |
"deletable": true, |
|
|
845 |
"editable": true |
|
|
846 |
}, |
|
|
847 |
"outputs": [ |
|
|
848 |
{ |
|
|
849 |
"name": "stderr", |
|
|
850 |
"output_type": "stream", |
|
|
851 |
"text": [ |
|
|
852 |
"2017-10-29 13:04:19,778 - T-CARER - INFO - Running Random Forest Classifier\n" |
|
|
853 |
] |
|
|
854 |
} |
|
|
855 |
], |
|
|
856 |
"source": [ |
|
|
857 |
"training_method = TrainingMethod(method_name)\n", |
|
|
858 |
"\n", |
|
|
859 |
"# file name\n", |
|
|
860 |
"file_name = \"Step_09_Model_\" + method_name + \"_\" + target_feature" |
|
|
861 |
] |
|
|
862 |
}, |
|
|
863 |
{ |
|
|
864 |
"cell_type": "markdown", |
|
|
865 |
"metadata": { |
|
|
866 |
"deletable": true, |
|
|
867 |
"editable": true |
|
|
868 |
}, |
|
|
869 |
"source": [ |
|
|
870 |
"Load the model" |
|
|
871 |
] |
|
|
872 |
}, |
|
|
873 |
{ |
|
|
874 |
"cell_type": "code", |
|
|
875 |
"execution_count": 20, |
|
|
876 |
"metadata": { |
|
|
877 |
"collapsed": false, |
|
|
878 |
"deletable": true, |
|
|
879 |
"editable": true |
|
|
880 |
}, |
|
|
881 |
"outputs": [ |
|
|
882 |
{ |
|
|
883 |
"name": "stderr", |
|
|
884 |
"output_type": "stream", |
|
|
885 |
"text": [ |
|
|
886 |
"2017-10-29 13:04:19,866 - T-CARER - INFO - Running Random Forest Classifier\n" |
|
|
887 |
] |
|
|
888 |
} |
|
|
889 |
], |
|
|
890 |
"source": [ |
|
|
891 |
"training_method.load(path=CONSTANTS.io_path, title=file_name)" |
|
|
892 |
] |
|
|
893 |
}, |
|
|
894 |
{ |
|
|
895 |
"cell_type": "markdown", |
|
|
896 |
"metadata": { |
|
|
897 |
"deletable": true, |
|
|
898 |
"editable": true |
|
|
899 |
}, |
|
|
900 |
"source": [ |
|
|
901 |
"#### <font style=\"font-weight:bold;color:blue\">2.4.2. TensorFlow Models</font>" |
|
|
902 |
] |
|
|
903 |
}, |
|
|
904 |
{ |
|
|
905 |
"cell_type": "code", |
|
|
906 |
"execution_count": 21, |
|
|
907 |
"metadata": { |
|
|
908 |
"collapsed": false, |
|
|
909 |
"deletable": true, |
|
|
910 |
"editable": true |
|
|
911 |
}, |
|
|
912 |
"outputs": [], |
|
|
913 |
"source": [ |
|
|
914 |
"class TrainingMethodTensorflow: \n", |
|
|
915 |
" def __init__(self, summaries, features_names, num_features, cut_off, train_size, test_size):\n", |
|
|
916 |
" self.model_predict = {\"train\": {'score': [], 'model_labels': []}, \n", |
|
|
917 |
" \"test\": {'score': [], 'model_labels': []}}\n", |
|
|
918 |
" self.__stats = Stats()\n", |
|
|
919 |
" # summaries[\"fit\"][\"get_variable_names\"]\n", |
|
|
920 |
" # summaries[\"fit\"][\"get_variable_value\"]\n", |
|
|
921 |
" # summaries[\"fit\"][\"get_params\"]\n", |
|
|
922 |
" # summaries[\"fit\"][\"export\"]\n", |
|
|
923 |
" # summaries[\"fit\"][\"get_variable_names()\"]\n", |
|
|
924 |
" # summaries[\"fit\"][\"params\"]\n", |
|
|
925 |
" # summaries[\"fit\"][\"dnn_bias_\"]\n", |
|
|
926 |
" # summaries[\"fit\"][\"dnn_weights_\"] \n", |
|
|
927 |
" # summaries[\"train\"][\"results\"]\n", |
|
|
928 |
" # summaries[\"test\"][\"results\"]\n", |
|
|
929 |
" \n", |
|
|
930 |
" self.model_predict[\"train\"]['pred'] = np.asarray([1 if i[1] >= 0.5 else 0 for i in summaries[\"train\"][\"predict_proba\"]][0:train_size])\n", |
|
|
931 |
" self.model_predict[\"test\"]['pred'] = np.asarray([1 if i[1] >= 0.5 else 0 for i in summaries[\"test\"][\"predict_proba\"]][0:test_size])\n", |
|
|
932 |
" \n", |
|
|
933 |
" self.model_predict[\"train\"]['score'] = np.asarray([i[1] for i in summaries[\"train\"][\"predict_proba\"]][0:train_size])\n", |
|
|
934 |
" self.model_predict[\"test\"]['score'] = np.asarray([i[1] for i in summaries[\"test\"][\"predict_proba\"]][0:test_size])\n", |
|
|
935 |
" \n", |
|
|
936 |
" self.model_predict[\"train\"]['score_0'] = np.asarray([i[0] for i in summaries[\"train\"][\"predict_proba\"]][0:train_size])\n", |
|
|
937 |
" self.model_predict[\"test\"]['score_0'] = np.asarray([i[0] for i in summaries[\"test\"][\"predict_proba\"]][0:test_size])\n", |
|
|
938 |
" \n", |
|
|
939 |
" def train_summaries(self):\n", |
|
|
940 |
" return {\"feature_importances_\": self.__weights}\n", |
|
|
941 |
" \n", |
|
|
942 |
" def predict_summaries(self, feature_target, sample_name):\n", |
|
|
943 |
" return self.__stats.predict_summaries(self.model_predict[sample_name], feature_target)" |
|
|
944 |
] |
|
|
945 |
}, |
|
|
946 |
{ |
|
|
947 |
"cell_type": "code", |
|
|
948 |
"execution_count": 22, |
|
|
949 |
"metadata": { |
|
|
950 |
"collapsed": false, |
|
|
951 |
"deletable": true, |
|
|
952 |
"editable": true |
|
|
953 |
}, |
|
|
954 |
"outputs": [ |
|
|
955 |
{ |
|
|
956 |
"name": "stderr", |
|
|
957 |
"output_type": "stream", |
|
|
958 |
"text": [ |
|
|
959 |
"2017-10-29 13:04:20,044 - T-CARER - ERROR - ReadersWriters._PickleSerialised - Can not open the file: \n", |
|
|
960 |
"C:\\Users\\eagle\\Documents\\GitHub\\tmp\\TCARER\\Basic_prototype\\model_tensorflow_summaries_label365.bz2\n", |
|
|
961 |
"\n" |
|
|
962 |
] |
|
|
963 |
}, |
|
|
964 |
{ |
|
|
965 |
"name": "stdout", |
|
|
966 |
"output_type": "stream", |
|
|
967 |
"text": [ |
|
|
968 |
"[Errno 2] No such file or directory: 'C:\\\\Users\\\\eagle\\\\Documents\\\\GitHub\\\\tmp\\\\TCARER\\\\Basic_prototype\\\\model_tensorflow_summaries_label365.bz2'\n" |
|
|
969 |
] |
|
|
970 |
}, |
|
|
971 |
{ |
|
|
972 |
"ename": "SystemExit", |
|
|
973 |
"evalue": "", |
|
|
974 |
"output_type": "error", |
|
|
975 |
"traceback": [ |
|
|
976 |
"An exception has occurred, use %tb to see the full traceback.\n", |
|
|
977 |
"\u001b[0;31mSystemExit\u001b[0m\n" |
|
|
978 |
] |
|
|
979 |
}, |
|
|
980 |
{ |
|
|
981 |
"name": "stderr", |
|
|
982 |
"output_type": "stream", |
|
|
983 |
"text": [ |
|
|
984 |
"c:\\users\\eagle\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\IPython\\core\\interactiveshell.py:2889: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.\n", |
|
|
985 |
" warn(\"To exit: use 'exit', 'quit', or Ctrl-D.\", stacklevel=1)\n" |
|
|
986 |
] |
|
|
987 |
} |
|
|
988 |
], |
|
|
989 |
"source": [ |
|
|
990 |
"file_name = \"model_tensorflow_summaries_\" + target_feature\n", |
|
|
991 |
"summaries = readers_writers.load_serialised_compressed(path=CONSTANTS.io_path, title=file_name)" |
|
|
992 |
] |
|
|
993 |
}, |
|
|
994 |
{ |
|
|
995 |
"cell_type": "code", |
|
|
996 |
"execution_count": null, |
|
|
997 |
"metadata": { |
|
|
998 |
"collapsed": false, |
|
|
999 |
"deletable": true, |
|
|
1000 |
"editable": true |
|
|
1001 |
}, |
|
|
1002 |
"outputs": [], |
|
|
1003 |
"source": [ |
|
|
1004 |
"num_features = 300\n", |
|
|
1005 |
"cut_off = 0.5\n", |
|
|
1006 |
"\n", |
|
|
1007 |
"training_method = TrainingMethodTensorflow(summaries, features_names_selected, num_features, cut_off,\n", |
|
|
1008 |
" len(features[\"train_indep\"].index), len(features[\"test_indep\"].index))" |
|
|
1009 |
] |
|
|
1010 |
}, |
|
|
1011 |
{ |
|
|
1012 |
"cell_type": "markdown", |
|
|
1013 |
"metadata": { |
|
|
1014 |
"deletable": true, |
|
|
1015 |
"editable": true |
|
|
1016 |
}, |
|
|
1017 |
"source": [ |
|
|
1018 |
"<br/><br/>" |
|
|
1019 |
] |
|
|
1020 |
}, |
|
|
1021 |
{ |
|
|
1022 |
"cell_type": "markdown", |
|
|
1023 |
"metadata": { |
|
|
1024 |
"deletable": true, |
|
|
1025 |
"editable": true |
|
|
1026 |
}, |
|
|
1027 |
"source": [ |
|
|
1028 |
"Performance" |
|
|
1029 |
] |
|
|
1030 |
}, |
|
|
1031 |
{ |
|
|
1032 |
"cell_type": "code", |
|
|
1033 |
"execution_count": 23, |
|
|
1034 |
"metadata": { |
|
|
1035 |
"collapsed": false, |
|
|
1036 |
"deletable": true, |
|
|
1037 |
"editable": true |
|
|
1038 |
}, |
|
|
1039 |
"outputs": [ |
|
|
1040 |
{ |
|
|
1041 |
"name": "stdout", |
|
|
1042 |
"output_type": "stream", |
|
|
1043 |
"text": [ |
|
|
1044 |
"accuracy_score 0.6592\n", |
|
|
1045 |
"average_precision_score 0.47970482114\n", |
|
|
1046 |
"brier_score_loss 0.218148003816\n", |
|
|
1047 |
"classification_report precision recall f1-score support\n", |
|
|
1048 |
"\n", |
|
|
1049 |
" 0 0.88 0.63 0.74 1885\n", |
|
|
1050 |
" 1 0.40 0.74 0.52 615\n", |
|
|
1051 |
"\n", |
|
|
1052 |
"avg / total 0.76 0.66 0.68 2500\n", |
|
|
1053 |
"\n", |
|
|
1054 |
"confusion_matrix [[1194 691]\n", |
|
|
1055 |
" [ 161 454]]\n", |
|
|
1056 |
"f1_score 0.515909090909\n", |
|
|
1057 |
"fbeta_score 0.436958614052\n", |
|
|
1058 |
"hamming_loss 0.3408\n", |
|
|
1059 |
"jaccard_similarity_score 0.6592\n", |
|
|
1060 |
"log_loss 11.7710360041\n", |
|
|
1061 |
"matthews_corrcoef 0.32124418171\n", |
|
|
1062 |
"precision_recall_fscore_support (array([ 0.88118081, 0.39650655]), array([ 0.63342175, 0.73821138]), array([ 0.73703704, 0.51590909]), array([1885, 615], dtype=int64))\n", |
|
|
1063 |
"precision_score 0.396506550218\n", |
|
|
1064 |
"recall_score 0.738211382114\n", |
|
|
1065 |
"roc_auc_score 0.742965646633\n", |
|
|
1066 |
"zero_one_loss 0.3408\n", |
|
|
1067 |
"\n", |
|
|
1068 |
"\n", |
|
|
1069 |
"accuracy_score 0.654661864746\n", |
|
|
1070 |
"average_precision_score 0.423030738094\n", |
|
|
1071 |
"brier_score_loss 0.22022287805\n", |
|
|
1072 |
"classification_report precision recall f1-score support\n", |
|
|
1073 |
"\n", |
|
|
1074 |
" 0 0.90 0.63 0.74 1959\n", |
|
|
1075 |
" 1 0.36 0.75 0.48 540\n", |
|
|
1076 |
"\n", |
|
|
1077 |
"avg / total 0.78 0.65 0.69 2499\n", |
|
|
1078 |
"\n", |
|
|
1079 |
"confusion_matrix [[1230 729]\n", |
|
|
1080 |
" [ 134 406]]\n", |
|
|
1081 |
"f1_score 0.484776119403\n", |
|
|
1082 |
"fbeta_score 0.399606299213\n", |
|
|
1083 |
"hamming_loss 0.345338135254\n", |
|
|
1084 |
"jaccard_similarity_score 0.654661864746\n", |
|
|
1085 |
"log_loss 11.9277898901\n", |
|
|
1086 |
"matthews_corrcoef 0.313889024973\n", |
|
|
1087 |
"precision_recall_fscore_support (array([ 0.90175953, 0.35770925]), array([ 0.62787136, 0.75185185]), array([ 0.74029491, 0.48477612]), array([1959, 540], dtype=int64))\n", |
|
|
1088 |
"precision_score 0.357709251101\n", |
|
|
1089 |
"recall_score 0.751851851852\n", |
|
|
1090 |
"roc_auc_score 0.73645898323\n", |
|
|
1091 |
"zero_one_loss 0.345338135254\n" |
|
|
1092 |
] |
|
|
1093 |
} |
|
|
1094 |
], |
|
|
1095 |
"source": [ |
|
|
1096 |
"# train\n", |
|
|
1097 |
"o_summaries = training_method.predict_summaries(features[\"train_target\"][target_feature], \"train\")\n", |
|
|
1098 |
"for k in o_summaries.keys():\n", |
|
|
1099 |
" print(k, o_summaries[k])\n", |
|
|
1100 |
" \n", |
|
|
1101 |
"print(\"\\n\")\n", |
|
|
1102 |
"# test\n", |
|
|
1103 |
"o_summaries = training_method.predict_summaries(features[\"test_target\"][target_feature], \"test\")\n", |
|
|
1104 |
"for k in o_summaries.keys():\n", |
|
|
1105 |
" print(k, o_summaries[k])" |
|
|
1106 |
] |
|
|
1107 |
}, |
|
|
1108 |
{ |
|
|
1109 |
"cell_type": "markdown", |
|
|
1110 |
"metadata": { |
|
|
1111 |
"deletable": true, |
|
|
1112 |
"editable": true |
|
|
1113 |
}, |
|
|
1114 |
"source": [ |
|
|
1115 |
"<br/><br/>" |
|
|
1116 |
] |
|
|
1117 |
}, |
|
|
1118 |
{ |
|
|
1119 |
"cell_type": "markdown", |
|
|
1120 |
"metadata": { |
|
|
1121 |
"deletable": true, |
|
|
1122 |
"editable": true |
|
|
1123 |
}, |
|
|
1124 |
"source": [ |
|
|
1125 |
"### 2.5. Load the Extra Features for Benchmarking" |
|
|
1126 |
] |
|
|
1127 |
}, |
|
|
1128 |
{ |
|
|
1129 |
"cell_type": "markdown", |
|
|
1130 |
"metadata": { |
|
|
1131 |
"deletable": true, |
|
|
1132 |
"editable": true |
|
|
1133 |
}, |
|
|
1134 |
"source": [ |
|
|
1135 |
"Read the extra features" |
|
|
1136 |
] |
|
|
1137 |
}, |
|
|
1138 |
{ |
|
|
1139 |
"cell_type": "code", |
|
|
1140 |
"execution_count": 24, |
|
|
1141 |
"metadata": { |
|
|
1142 |
"collapsed": false, |
|
|
1143 |
"deletable": true, |
|
|
1144 |
"editable": true |
|
|
1145 |
}, |
|
|
1146 |
"outputs": [], |
|
|
1147 |
"source": [ |
|
|
1148 |
"table = 'tcarer_featuresExtra'\n", |
|
|
1149 |
"features_extra_dtypes = {'patientID': 'U32', 'trigger_charlsonFoster': 'i4', 'trigger_los': 'i4', 'trigger_age': 'i4', 'prior_admiOther': 'i4', 'prior_admiAcute': 'i4', \n", |
|
|
1150 |
" 'prior_spells': 'i4', 'prior_asthma': 'i4', 'prior_copd': 'i4', 'prior_depression': 'i4', 'prior_diabetes': 'i4', 'prior_hypertension': 'i4', 'prior_cancer': 'i4', 'prior_chd': 'i4', 'prior_chf': 'i4', \n", |
|
|
1151 |
" 'diagCci_01_myocardial_freq': 'i4', 'diagCci_02_chf_freq': 'i4', 'diagCci_03_pvd_freq': 'i4', 'diagCci_04_cerebrovascular_freq': 'i4', 'diagCci_05_dementia_freq': 'i4', 'diagCci_06_cpd_freq': 'i4', 'diagCci_07_rheumatic_freq': 'i4', 'diagCci_08_ulcer_freq': 'i4', 'diagCci_09_liverMild_freq': 'i4', 'diagCci_10_diabetesNotChronic_freq': 'i4', 'diagCci_11_diabetesChronic_freq': 'i4', 'diagCci_12_hemiplegia_freq': 'i4', 'diagCci_13_renal_freq': 'i4', 'diagCci_14_malignancy_freq': 'i4', 'diagCci_15_liverSevere_freq': 'i4', 'diagCci_16_tumorSec_freq': 'i4', 'diagCci_17_aids_freq': 'i4', 'diagCci_18_depression_freq': 'i4', 'diagCci_19_cardiac_freq': 'i4', 'diagCci_20_valvular_freq': 'i4', 'diagCci_21_pulmonary_freq': 'i4', 'diagCci_22_vascular_freq': 'i4', 'diagCci_23_hypertensionNotComplicated_freq': 'i4', 'diagCci_24_hypertensionComplicated_freq': 'i4', 'diagCci_25_paralysis_freq': 'i4', 'diagCci_26_neuroOther_freq': 'i4', 'diagCci_27_pulmonaryChronic_freq': 'i4', 'diagCci_28_diabetesNotComplicated_freq': 'i4', 'diagCci_29_diabetesComplicated_freq': 'i4', 'diagCci_30_hypothyroidism_freq': 'i4', 'diagCci_31_renal_freq': 'i4', 'diagCci_32_liver_freq': 'i4', 'diagCci_33_ulcerNotBleeding_freq': 'i4', 'diagCci_34_psychoses_freq': 'i4', 'diagCci_35_lymphoma_freq': 'i4', 'diagCci_36_cancerSec_freq': 'i4', 'diagCci_37_tumorNotSec_freq': 'i4', 'diagCci_38_rheumatoid_freq': 'i4', 'diagCci_39_coagulopathy_freq': 'i4', 'diagCci_40_obesity_freq': 'i4', 'diagCci_41_weightLoss_freq': 'i4', 'diagCci_42_fluidDisorder_freq': 'i4', 'diagCci_43_bloodLoss_freq': 'i4', 'diagCci_44_anemia_freq': 'i4', 'diagCci_45_alcohol_freq': 'i4', 'diagCci_46_drug_freq': 'i4'}\n", |
|
|
1152 |
"features_extra_name = features_extra_dtypes.keys()" |
|
|
1153 |
] |
|
|
1154 |
}, |
|
|
1155 |
{ |
|
|
1156 |
"cell_type": "code", |
|
|
1157 |
"execution_count": 25, |
|
|
1158 |
"metadata": { |
|
|
1159 |
"collapsed": false, |
|
|
1160 |
"deletable": true, |
|
|
1161 |
"editable": true |
|
|
1162 |
}, |
|
|
1163 |
"outputs": [ |
|
|
1164 |
{ |
|
|
1165 |
"ename": "ProgrammingError", |
|
|
1166 |
"evalue": "(_mysql_exceptions.ProgrammingError) (1146, \"Table 'parr_sample_prototype.tcarer_featuresextra' doesn't exist\") [SQL: 'SELECT * FROM tcarer_featuresExtra']", |
|
|
1167 |
"output_type": "error", |
|
|
1168 |
"traceback": [ |
|
|
1169 |
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", |
|
|
1170 |
"\u001b[0;31mProgrammingError\u001b[0m Traceback (most recent call last)", |
|
|
1171 |
"\u001b[0;32mc:\\users\\eagle\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\sqlalchemy\\engine\\base.py\u001b[0m in \u001b[0;36m_execute_context\u001b[0;34m(self, dialect, constructor, statement, parameters, *args)\u001b[0m\n\u001b[1;32m 1181\u001b[0m \u001b[0mparameters\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1182\u001b[0;31m context)\n\u001b[0m\u001b[1;32m 1183\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mBaseException\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", |
|
|
1172 |
"\u001b[0;32mc:\\users\\eagle\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\sqlalchemy\\engine\\default.py\u001b[0m in \u001b[0;36mdo_execute\u001b[0;34m(self, cursor, statement, parameters, context)\u001b[0m\n\u001b[1;32m 469\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mdo_execute\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcursor\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstatement\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparameters\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcontext\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 470\u001b[0;31m \u001b[0mcursor\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mexecute\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mstatement\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparameters\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 471\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", |
|
|
1173 |
"\u001b[0;32mc:\\users\\eagle\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\MySQLdb\\cursors.py\u001b[0m in \u001b[0;36mexecute\u001b[0;34m(self, query, args)\u001b[0m\n\u001b[1;32m 249\u001b[0m \u001b[0mexc\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mvalue\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0msys\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mexc_info\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 250\u001b[0;31m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0merrorhandler\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mexc\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mvalue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 251\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_executed\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mquery\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", |
|
|
1174 |
"\u001b[0;32mc:\\users\\eagle\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\MySQLdb\\connections.py\u001b[0m in \u001b[0;36mdefaulterrorhandler\u001b[0;34m(***failed resolving arguments***)\u001b[0m\n\u001b[1;32m 41\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0merrorvalue\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mBaseException\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m---> 42\u001b[0;31m \u001b[1;32mraise\u001b[0m \u001b[0merrorvalue\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 43\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0merrorclass\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", |
|
|
1175 |
"\u001b[0;32mc:\\users\\eagle\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\MySQLdb\\cursors.py\u001b[0m in \u001b[0;36mexecute\u001b[0;34m(self, query, args)\u001b[0m\n\u001b[1;32m 246\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 247\u001b[0;31m \u001b[0mres\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_query\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mquery\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 248\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mException\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", |
|
|
1176 |
"\u001b[0;32mc:\\users\\eagle\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\MySQLdb\\cursors.py\u001b[0m in \u001b[0;36m_query\u001b[0;34m(self, q)\u001b[0m\n\u001b[1;32m 410\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_query\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mq\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 411\u001b[0;31m \u001b[0mrowcount\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_do_query\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mq\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 412\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_post_get_result\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", |
|
|
1177 |
"\u001b[0;32mc:\\users\\eagle\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\MySQLdb\\cursors.py\u001b[0m in \u001b[0;36m_do_query\u001b[0;34m(self, q)\u001b[0m\n\u001b[1;32m 373\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_last_executed\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mq\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 374\u001b[0;31m \u001b[0mdb\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mquery\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mq\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 375\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_do_get_result\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", |
|
|
1178 |
"\u001b[0;32mc:\\users\\eagle\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\MySQLdb\\connections.py\u001b[0m in \u001b[0;36mquery\u001b[0;34m(self, query)\u001b[0m\n\u001b[1;32m 269\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 270\u001b[0;31m \u001b[0m_mysql\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mconnection\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mquery\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mquery\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 271\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", |
|
|
1179 |
"\u001b[0;31mProgrammingError\u001b[0m: (1146, \"Table 'parr_sample_prototype.tcarer_featuresextra' doesn't exist\")", |
|
|
1180 |
"\nThe above exception was the direct cause of the following exception:\n", |
|
|
1181 |
"\u001b[0;31mProgrammingError\u001b[0m Traceback (most recent call last)", |
|
|
1182 |
"\u001b[0;32m<ipython-input-25-086a730ff34b>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[1;31m# Read features from the MySQL\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mfeatures_extra\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdict\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mfeatures_extra\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'train'\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mreaders_writers\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mload_mysql_table\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mschema\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtable\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdataframing\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mTrue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0mfeatures_extra\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'train'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mastype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdtype\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mfeatures_extra_dtypes\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mfeatures_extra\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'test'\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mfeatures_extra\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'train'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", |
|
|
1183 |
"\u001b[0;32mC:\\Users\\eagle\\Documents\\GitHub\\Analytics_UoW\\TCARER\\ReadersWriters\\ReadersWriters.py\u001b[0m in \u001b[0;36mload_mysql_table\u001b[0;34m(db_schema, db_table, dataframing)\u001b[0m\n\u001b[1;32m 323\u001b[0m \"\"\"\n\u001b[1;32m 324\u001b[0m \u001b[0mquery\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m\"SELECT * FROM \"\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mdb_table\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 325\u001b[0;31m \u001b[1;32mreturn\u001b[0m \u001b[0mReadersWriters\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mload_mysql_query\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mquery\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdb_schema\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdataframing\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 326\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 327\u001b[0m \u001b[1;33m@\u001b[0m\u001b[0mstaticmethod\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", |
|
|
1184 |
"\u001b[0;32mC:\\Users\\eagle\\Documents\\GitHub\\Analytics_UoW\\TCARER\\ReadersWriters\\ReadersWriters.py\u001b[0m in \u001b[0;36mload_mysql_query\u001b[0;34m(query, db_schema, dataframing, batch, float_round_vars, float_round)\u001b[0m\n\u001b[1;32m 345\u001b[0m \u001b[0mengine\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdb\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 346\u001b[0m \u001b[0mdbc\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mMysqlCommand\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mengine\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdb\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdb_session_vars\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 347\u001b[0;31m \u001b[0moutput\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdbc\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mread\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mquery\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdataframing\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbatch\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfloat_round_vars\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfloat_round\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 348\u001b[0m \u001b[0mdb\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mclose\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 349\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0moutput\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", |
|
|
1185 |
"\u001b[0;32mC:\\Users\\eagle\\Documents\\GitHub\\Analytics_UoW\\TCARER\\ReadersWriters\\_MysqlCommand.py\u001b[0m in \u001b[0;36mread\u001b[0;34m(self, query, dataframing, batch, float_round_vars, float_round)\u001b[0m\n\u001b[1;32m 71\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__logger\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdebug\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Reading from MySQL database.\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 72\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mdataframing\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m---> 73\u001b[0;31m \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__read_df\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mquery\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbatch\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfloat_round_vars\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfloat_round\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 74\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 75\u001b[0m \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__read_arr\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mquery\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", |
|
|
1186 |
"\u001b[0;32mC:\\Users\\eagle\\Documents\\GitHub\\Analytics_UoW\\TCARER\\ReadersWriters\\_MysqlCommand.py\u001b[0m in \u001b[0;36m__read_df\u001b[0;34m(self, query, batch, float_round_vars, float_round)\u001b[0m\n\u001b[1;32m 104\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 105\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mbatch\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 106\u001b[0;31m \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpds\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mread_sql\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msql\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mquery\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcon\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mconn\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcoerce_float\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mFalse\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mchunksize\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mbatch\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 107\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 108\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mdf\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mpds\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mread_sql\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msql\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mquery\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcon\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mconn\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcoerce_float\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mFalse\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mchunksize\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mbatch\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", |
|
|
1187 |
"\u001b[0;32mc:\\users\\eagle\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\pandas\\io\\sql.py\u001b[0m in \u001b[0;36mread_sql\u001b[0;34m(sql, con, index_col, coerce_float, params, parse_dates, columns, chunksize)\u001b[0m\n\u001b[1;32m 413\u001b[0m \u001b[0msql\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mindex_col\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mindex_col\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mparams\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 414\u001b[0m \u001b[0mcoerce_float\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mcoerce_float\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparse_dates\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mparse_dates\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 415\u001b[0;31m chunksize=chunksize)\n\u001b[0m\u001b[1;32m 416\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 417\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", |
|
|
1188 |
"\u001b[0;32mc:\\users\\eagle\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\pandas\\io\\sql.py\u001b[0m in \u001b[0;36mread_query\u001b[0;34m(self, sql, index_col, coerce_float, parse_dates, params, chunksize)\u001b[0m\n\u001b[1;32m 1082\u001b[0m \u001b[0margs\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0m_convert_params\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msql\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 1083\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1084\u001b[0;31m \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mexecute\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1085\u001b[0m \u001b[0mcolumns\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mresult\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mkeys\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 1086\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", |
|
|
1189 |
"\u001b[0;32mc:\\users\\eagle\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\pandas\\io\\sql.py\u001b[0m in \u001b[0;36mexecute\u001b[0;34m(self, *args, **kwargs)\u001b[0m\n\u001b[1;32m 973\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mexecute\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 974\u001b[0m \u001b[1;34m\"\"\"Simple passthrough to SQLAlchemy connectable\"\"\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 975\u001b[0;31m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mconnectable\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mexecute\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 976\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 977\u001b[0m def read_table(self, table_name, index_col=None, coerce_float=True,\n", |
|
|
1190 |
"\u001b[0;32mc:\\users\\eagle\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\sqlalchemy\\engine\\base.py\u001b[0m in \u001b[0;36mexecute\u001b[0;34m(self, object, *multiparams, **params)\u001b[0m\n\u001b[1;32m 937\u001b[0m \"\"\"\n\u001b[1;32m 938\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mobject\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mutil\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mstring_types\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 939\u001b[0;31m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_execute_text\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mobject\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmultiparams\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparams\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 940\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 941\u001b[0m \u001b[0mmeth\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mobject\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_execute_on_connection\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", |
|
|
1191 |
"\u001b[0;32mc:\\users\\eagle\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\sqlalchemy\\engine\\base.py\u001b[0m in \u001b[0;36m_execute_text\u001b[0;34m(self, statement, multiparams, params)\u001b[0m\n\u001b[1;32m 1095\u001b[0m \u001b[0mstatement\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 1096\u001b[0m \u001b[0mparameters\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1097\u001b[0;31m \u001b[0mstatement\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparameters\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1098\u001b[0m )\n\u001b[1;32m 1099\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_has_events\u001b[0m \u001b[1;32mor\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mengine\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_has_events\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", |
|
|
1192 |
"\u001b[0;32mc:\\users\\eagle\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\sqlalchemy\\engine\\base.py\u001b[0m in \u001b[0;36m_execute_context\u001b[0;34m(self, dialect, constructor, statement, parameters, *args)\u001b[0m\n\u001b[1;32m 1187\u001b[0m \u001b[0mparameters\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 1188\u001b[0m \u001b[0mcursor\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1189\u001b[0;31m context)\n\u001b[0m\u001b[1;32m 1190\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 1191\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_has_events\u001b[0m \u001b[1;32mor\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mengine\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_has_events\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", |
|
|
1193 |
"\u001b[0;32mc:\\users\\eagle\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\sqlalchemy\\engine\\base.py\u001b[0m in \u001b[0;36m_handle_dbapi_exception\u001b[0;34m(self, e, statement, parameters, cursor, context)\u001b[0m\n\u001b[1;32m 1391\u001b[0m util.raise_from_cause(\n\u001b[1;32m 1392\u001b[0m \u001b[0msqlalchemy_exception\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1393\u001b[0;31m \u001b[0mexc_info\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1394\u001b[0m )\n\u001b[1;32m 1395\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", |
|
|
1194 |
"\u001b[0;32mc:\\users\\eagle\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\sqlalchemy\\util\\compat.py\u001b[0m in \u001b[0;36mraise_from_cause\u001b[0;34m(exception, exc_info)\u001b[0m\n\u001b[1;32m 201\u001b[0m \u001b[0mexc_type\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mexc_value\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mexc_tb\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mexc_info\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 202\u001b[0m \u001b[0mcause\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mexc_value\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mexc_value\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mexception\u001b[0m \u001b[1;32melse\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 203\u001b[0;31m \u001b[0mreraise\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mexception\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mexception\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtb\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mexc_tb\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcause\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mcause\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 204\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 205\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mpy3k\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", |
|
|
1195 |
"\u001b[0;32mc:\\users\\eagle\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\sqlalchemy\\util\\compat.py\u001b[0m in \u001b[0;36mreraise\u001b[0;34m(tp, value, tb, cause)\u001b[0m\n\u001b[1;32m 184\u001b[0m \u001b[0mvalue\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__cause__\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mcause\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 185\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mvalue\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__traceback__\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mtb\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 186\u001b[0;31m \u001b[1;32mraise\u001b[0m \u001b[0mvalue\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mwith_traceback\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtb\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 187\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0mvalue\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 188\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", |
|
|
1196 |
"\u001b[0;32mc:\\users\\eagle\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\sqlalchemy\\engine\\base.py\u001b[0m in \u001b[0;36m_execute_context\u001b[0;34m(self, dialect, constructor, statement, parameters, *args)\u001b[0m\n\u001b[1;32m 1180\u001b[0m \u001b[0mstatement\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 1181\u001b[0m \u001b[0mparameters\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1182\u001b[0;31m context)\n\u001b[0m\u001b[1;32m 1183\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mBaseException\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 1184\u001b[0m self._handle_dbapi_exception(\n", |
|
|
1197 |
"\u001b[0;32mc:\\users\\eagle\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\sqlalchemy\\engine\\default.py\u001b[0m in \u001b[0;36mdo_execute\u001b[0;34m(self, cursor, statement, parameters, context)\u001b[0m\n\u001b[1;32m 468\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 469\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mdo_execute\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcursor\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstatement\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparameters\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcontext\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 470\u001b[0;31m \u001b[0mcursor\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mexecute\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mstatement\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mparameters\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 471\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 472\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mdo_execute_no_params\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcursor\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstatement\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcontext\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", |
|
|
1198 |
"\u001b[0;32mc:\\users\\eagle\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\MySQLdb\\cursors.py\u001b[0m in \u001b[0;36mexecute\u001b[0;34m(self, query, args)\u001b[0m\n\u001b[1;32m 248\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mException\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 249\u001b[0m \u001b[0mexc\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mvalue\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0msys\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mexc_info\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 250\u001b[0;31m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0merrorhandler\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mexc\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mvalue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 251\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_executed\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mquery\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 252\u001b[0m \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_defer_warnings\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", |
|
|
1199 |
"\u001b[0;32mc:\\users\\eagle\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\MySQLdb\\connections.py\u001b[0m in \u001b[0;36mdefaulterrorhandler\u001b[0;34m(***failed resolving arguments***)\u001b[0m\n\u001b[1;32m 40\u001b[0m \u001b[1;32mdel\u001b[0m \u001b[0mconnection\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 41\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0merrorvalue\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mBaseException\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m---> 42\u001b[0;31m \u001b[1;32mraise\u001b[0m \u001b[0merrorvalue\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 43\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0merrorclass\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 44\u001b[0m \u001b[1;32mraise\u001b[0m \u001b[0merrorclass\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0merrorvalue\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", |
|
|
1200 |
"\u001b[0;32mc:\\users\\eagle\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\MySQLdb\\cursors.py\u001b[0m in \u001b[0;36mexecute\u001b[0;34m(self, query, args)\u001b[0m\n\u001b[1;32m 245\u001b[0m \u001b[0mres\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 246\u001b[0m \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 247\u001b[0;31m \u001b[0mres\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_query\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mquery\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 248\u001b[0m \u001b[1;32mexcept\u001b[0m \u001b[0mException\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 249\u001b[0m \u001b[0mexc\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mvalue\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0msys\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mexc_info\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", |
|
|
1201 |
"\u001b[0;32mc:\\users\\eagle\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\MySQLdb\\cursors.py\u001b[0m in \u001b[0;36m_query\u001b[0;34m(self, q)\u001b[0m\n\u001b[1;32m 409\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 410\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_query\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mq\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 411\u001b[0;31m \u001b[0mrowcount\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_do_query\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mq\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 412\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_post_get_result\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 413\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mrowcount\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", |
|
|
1202 |
"\u001b[0;32mc:\\users\\eagle\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\MySQLdb\\cursors.py\u001b[0m in \u001b[0;36m_do_query\u001b[0;34m(self, q)\u001b[0m\n\u001b[1;32m 372\u001b[0m \u001b[0mdb\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_get_db\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 373\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_last_executed\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mq\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 374\u001b[0;31m \u001b[0mdb\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mquery\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mq\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 375\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_do_get_result\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 376\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrowcount\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", |
|
|
1203 |
"\u001b[0;32mc:\\users\\eagle\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\MySQLdb\\connections.py\u001b[0m in \u001b[0;36mquery\u001b[0;34m(self, query)\u001b[0m\n\u001b[1;32m 268\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mread_query_result\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 269\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m--> 270\u001b[0;31m \u001b[0m_mysql\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mconnection\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mquery\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mquery\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 271\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m 272\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m__enter__\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", |
|
|
1204 |
"\u001b[0;31mProgrammingError\u001b[0m: (_mysql_exceptions.ProgrammingError) (1146, \"Table 'parr_sample_prototype.tcarer_featuresextra' doesn't exist\") [SQL: 'SELECT * FROM tcarer_featuresExtra']" |
|
|
1205 |
] |
|
|
1206 |
} |
|
|
1207 |
], |
|
|
1208 |
"source": [ |
|
|
1209 |
"# Read features from the MySQL\n", |
|
|
1210 |
"features_extra = dict()\n", |
|
|
1211 |
"features_extra['train'] = readers_writers.load_mysql_table(schema, table, dataframing=True)\n", |
|
|
1212 |
"features_extra['train'].astype(dtype=features_extra_dtypes)\n", |
|
|
1213 |
"features_extra['test'] = features_extra['train']\n", |
|
|
1214 |
"\n", |
|
|
1215 |
"print(\"Number of columns: \", len(features_extra['train'].columns), \"; Total records: \", len(features_extra['train'].index))" |
|
|
1216 |
] |
|
|
1217 |
}, |
|
|
1218 |
{ |
|
|
1219 |
"cell_type": "markdown", |
|
|
1220 |
"metadata": { |
|
|
1221 |
"deletable": true, |
|
|
1222 |
"editable": true |
|
|
1223 |
}, |
|
|
1224 |
"source": [ |
|
|
1225 |
"Replace NaN appears in the Charlson-Index feature " |
|
|
1226 |
] |
|
|
1227 |
}, |
|
|
1228 |
{ |
|
|
1229 |
"cell_type": "code", |
|
|
1230 |
"execution_count": null, |
|
|
1231 |
"metadata": { |
|
|
1232 |
"collapsed": true, |
|
|
1233 |
"deletable": true, |
|
|
1234 |
"editable": true |
|
|
1235 |
}, |
|
|
1236 |
"outputs": [], |
|
|
1237 |
"source": [ |
|
|
1238 |
"features_extra['train'].loc[:, \"trigger_charlsonFoster\"] = np.nan_to_num(features_extra['train'][\"trigger_charlsonFoster\"])\n", |
|
|
1239 |
"features_extra['test'].loc[:, \"trigger_charlsonFoster\"] = np.nan_to_num(features_extra['test'][\"trigger_charlsonFoster\"])" |
|
|
1240 |
] |
|
|
1241 |
}, |
|
|
1242 |
{ |
|
|
1243 |
"cell_type": "markdown", |
|
|
1244 |
"metadata": { |
|
|
1245 |
"deletable": true, |
|
|
1246 |
"editable": true |
|
|
1247 |
}, |
|
|
1248 |
"source": [ |
|
|
1249 |
"Combine (join by PatientID)" |
|
|
1250 |
] |
|
|
1251 |
}, |
|
|
1252 |
{ |
|
|
1253 |
"cell_type": "code", |
|
|
1254 |
"execution_count": null, |
|
|
1255 |
"metadata": { |
|
|
1256 |
"collapsed": false, |
|
|
1257 |
"deletable": true, |
|
|
1258 |
"editable": true |
|
|
1259 |
}, |
|
|
1260 |
"outputs": [], |
|
|
1261 |
"source": [ |
|
|
1262 |
"features_extra['train'] = features_extra['train'].merge(\n", |
|
|
1263 |
" pd.concat([features['train_id'], features['train_target'], \n", |
|
|
1264 |
" pd.DataFrame({'score': training_method.model_predict[\"train\"]['score']}), features['train_indep']], axis=1), \n", |
|
|
1265 |
" how=\"inner\", on=\"patientID\")\n", |
|
|
1266 |
"features_extra['test'] = features_extra['test'].merge(\n", |
|
|
1267 |
" pd.concat([features['test_id'], features['test_target'], \n", |
|
|
1268 |
" pd.DataFrame({'score': training_method.model_predict[\"test\"]['score']}), features['test_indep']], axis=1), \n", |
|
|
1269 |
" how=\"inner\", on=\"patientID\")" |
|
|
1270 |
] |
|
|
1271 |
}, |
|
|
1272 |
{ |
|
|
1273 |
"cell_type": "markdown", |
|
|
1274 |
"metadata": { |
|
|
1275 |
"deletable": true, |
|
|
1276 |
"editable": true |
|
|
1277 |
}, |
|
|
1278 |
"source": [ |
|
|
1279 |
"<font style=\"font-weight:bold;color:red\">Clean-up</font>" |
|
|
1280 |
] |
|
|
1281 |
}, |
|
|
1282 |
{ |
|
|
1283 |
"cell_type": "code", |
|
|
1284 |
"execution_count": null, |
|
|
1285 |
"metadata": { |
|
|
1286 |
"collapsed": false, |
|
|
1287 |
"deletable": true, |
|
|
1288 |
"editable": true, |
|
|
1289 |
"scrolled": true |
|
|
1290 |
}, |
|
|
1291 |
"outputs": [], |
|
|
1292 |
"source": [ |
|
|
1293 |
"features = None\n", |
|
|
1294 |
"gc.collect()" |
|
|
1295 |
] |
|
|
1296 |
}, |
|
|
1297 |
{ |
|
|
1298 |
"cell_type": "markdown", |
|
|
1299 |
"metadata": { |
|
|
1300 |
"deletable": true, |
|
|
1301 |
"editable": true |
|
|
1302 |
}, |
|
|
1303 |
"source": [ |
|
|
1304 |
"<br/><br/>" |
|
|
1305 |
] |
|
|
1306 |
}, |
|
|
1307 |
{ |
|
|
1308 |
"cell_type": "markdown", |
|
|
1309 |
"metadata": { |
|
|
1310 |
"deletable": true, |
|
|
1311 |
"editable": true |
|
|
1312 |
}, |
|
|
1313 |
"source": [ |
|
|
1314 |
"## 3. Charlson Index Model" |
|
|
1315 |
] |
|
|
1316 |
}, |
|
|
1317 |
{ |
|
|
1318 |
"cell_type": "markdown", |
|
|
1319 |
"metadata": { |
|
|
1320 |
"deletable": true, |
|
|
1321 |
"editable": true |
|
|
1322 |
}, |
|
|
1323 |
"source": [ |
|
|
1324 |
"### 3.1. Algorithm" |
|
|
1325 |
] |
|
|
1326 |
}, |
|
|
1327 |
{ |
|
|
1328 |
"cell_type": "markdown", |
|
|
1329 |
"metadata": { |
|
|
1330 |
"deletable": true, |
|
|
1331 |
"editable": true |
|
|
1332 |
}, |
|
|
1333 |
"source": [ |
|
|
1334 |
"<font style=\"font-weight:bold;color:brown\">Algorithm 1</font>: Random Forest" |
|
|
1335 |
] |
|
|
1336 |
}, |
|
|
1337 |
{ |
|
|
1338 |
"cell_type": "code", |
|
|
1339 |
"execution_count": null, |
|
|
1340 |
"metadata": { |
|
|
1341 |
"collapsed": false, |
|
|
1342 |
"deletable": true, |
|
|
1343 |
"editable": true |
|
|
1344 |
}, |
|
|
1345 |
"outputs": [], |
|
|
1346 |
"source": [ |
|
|
1347 |
"charlson_method_name = \"rfc\"\n", |
|
|
1348 |
"kwargs = {\"n_estimators\": 20, \"criterion\": 'gini', \"max_depth\": None, \"min_samples_split\": 100,\n", |
|
|
1349 |
" \"min_samples_leaf\": 50, \"min_weight_fraction_leaf\": 0.0, \"max_features\": 'auto',\n", |
|
|
1350 |
" \"max_leaf_nodes\": None, \"bootstrap\": True, \"oob_score\": False, \"n_jobs\": -1, \"random_state\": None,\n", |
|
|
1351 |
" \"verbose\": 0, \"warm_start\": False, \"class_weight\": \"balanced_subsample\"}" |
|
|
1352 |
] |
|
|
1353 |
}, |
|
|
1354 |
{ |
|
|
1355 |
"cell_type": "markdown", |
|
|
1356 |
"metadata": { |
|
|
1357 |
"deletable": true, |
|
|
1358 |
"editable": true |
|
|
1359 |
}, |
|
|
1360 |
"source": [ |
|
|
1361 |
"<font style=\"font-weight:bold;color:brown\">Algorithm 2</font>: Logistic Regression" |
|
|
1362 |
] |
|
|
1363 |
}, |
|
|
1364 |
{ |
|
|
1365 |
"cell_type": "code", |
|
|
1366 |
"execution_count": null, |
|
|
1367 |
"metadata": { |
|
|
1368 |
"collapsed": false, |
|
|
1369 |
"deletable": true, |
|
|
1370 |
"editable": true |
|
|
1371 |
}, |
|
|
1372 |
"outputs": [], |
|
|
1373 |
"source": [ |
|
|
1374 |
"charlson_method_name = \"lr\"\n", |
|
|
1375 |
"kwargs = {\"penalty\": 'l2', \"dual\": False, \"tol\": 0.0001, \"C\": 1, \"fit_intercept\": True, \"intercept_scaling\": 1,\n", |
|
|
1376 |
" \"class_weight\": None, \"random_state\": None, \"solver\": 'liblinear', \"max_iter\": 100, \"multi_class\": 'ovr',\n", |
|
|
1377 |
" \"verbose\": 0, \"warm_start\": False, \"n_jobs\": -1}" |
|
|
1378 |
] |
|
|
1379 |
}, |
|
|
1380 |
{ |
|
|
1381 |
"cell_type": "markdown", |
|
|
1382 |
"metadata": { |
|
|
1383 |
"deletable": true, |
|
|
1384 |
"editable": true |
|
|
1385 |
}, |
|
|
1386 |
"source": [ |
|
|
1387 |
"<br/><br/>" |
|
|
1388 |
] |
|
|
1389 |
}, |
|
|
1390 |
{ |
|
|
1391 |
"cell_type": "markdown", |
|
|
1392 |
"metadata": { |
|
|
1393 |
"deletable": true, |
|
|
1394 |
"editable": true |
|
|
1395 |
}, |
|
|
1396 |
"source": [ |
|
|
1397 |
"### 3.2. Initialise" |
|
|
1398 |
] |
|
|
1399 |
}, |
|
|
1400 |
{ |
|
|
1401 |
"cell_type": "code", |
|
|
1402 |
"execution_count": null, |
|
|
1403 |
"metadata": { |
|
|
1404 |
"collapsed": false, |
|
|
1405 |
"deletable": true, |
|
|
1406 |
"editable": true |
|
|
1407 |
}, |
|
|
1408 |
"outputs": [], |
|
|
1409 |
"source": [ |
|
|
1410 |
"# set features\n", |
|
|
1411 |
"charlson_features_names = ['trigger_charlsonFoster']" |
|
|
1412 |
] |
|
|
1413 |
}, |
|
|
1414 |
{ |
|
|
1415 |
"cell_type": "code", |
|
|
1416 |
"execution_count": null, |
|
|
1417 |
"metadata": { |
|
|
1418 |
"collapsed": false, |
|
|
1419 |
"deletable": true, |
|
|
1420 |
"editable": true |
|
|
1421 |
}, |
|
|
1422 |
"outputs": [], |
|
|
1423 |
"source": [ |
|
|
1424 |
"# select the target variable\n", |
|
|
1425 |
"charlson_target_feature = \"label30\" # \"label30\", \"label365\" \n", |
|
|
1426 |
"\n", |
|
|
1427 |
"# file name\n", |
|
|
1428 |
"file_name = \"report_Model_Charlson_\" + charlson_method_name + \"_\" + charlson_target_feature\n", |
|
|
1429 |
"\n", |
|
|
1430 |
"# initialise\n", |
|
|
1431 |
"charlson_training_method = TrainingMethod(charlson_method_name)" |
|
|
1432 |
] |
|
|
1433 |
}, |
|
|
1434 |
{ |
|
|
1435 |
"cell_type": "markdown", |
|
|
1436 |
"metadata": { |
|
|
1437 |
"deletable": true, |
|
|
1438 |
"editable": true |
|
|
1439 |
}, |
|
|
1440 |
"source": [ |
|
|
1441 |
"### 3.3. Fit" |
|
|
1442 |
] |
|
|
1443 |
}, |
|
|
1444 |
{ |
|
|
1445 |
"cell_type": "markdown", |
|
|
1446 |
"metadata": { |
|
|
1447 |
"deletable": true, |
|
|
1448 |
"editable": true |
|
|
1449 |
}, |
|
|
1450 |
"source": [ |
|
|
1451 |
"Fit Model" |
|
|
1452 |
] |
|
|
1453 |
}, |
|
|
1454 |
{ |
|
|
1455 |
"cell_type": "code", |
|
|
1456 |
"execution_count": null, |
|
|
1457 |
"metadata": { |
|
|
1458 |
"collapsed": false, |
|
|
1459 |
"deletable": true, |
|
|
1460 |
"editable": true |
|
|
1461 |
}, |
|
|
1462 |
"outputs": [], |
|
|
1463 |
"source": [ |
|
|
1464 |
"o_summaries = dict()\n", |
|
|
1465 |
"# Fit\n", |
|
|
1466 |
"model = charlson_training_method.train(features_extra[\"train\"][charlson_features_names], features_extra[\"train\"][target_feature], **kwargs)\n", |
|
|
1467 |
"charlson_training_method.save_model(path=CONSTANTS.io_path, title=file_name)" |
|
|
1468 |
] |
|
|
1469 |
}, |
|
|
1470 |
{ |
|
|
1471 |
"cell_type": "code", |
|
|
1472 |
"execution_count": null, |
|
|
1473 |
"metadata": { |
|
|
1474 |
"collapsed": true, |
|
|
1475 |
"deletable": true, |
|
|
1476 |
"editable": true |
|
|
1477 |
}, |
|
|
1478 |
"outputs": [], |
|
|
1479 |
"source": [ |
|
|
1480 |
"# load model\n", |
|
|
1481 |
"# charlson_training_method.load(path=CONSTANTS.io_path, title=file_name)" |
|
|
1482 |
] |
|
|
1483 |
}, |
|
|
1484 |
{ |
|
|
1485 |
"cell_type": "code", |
|
|
1486 |
"execution_count": null, |
|
|
1487 |
"metadata": { |
|
|
1488 |
"collapsed": false, |
|
|
1489 |
"deletable": true, |
|
|
1490 |
"editable": true |
|
|
1491 |
}, |
|
|
1492 |
"outputs": [], |
|
|
1493 |
"source": [ |
|
|
1494 |
"# short summary\n", |
|
|
1495 |
"o_summaries = charlson_training_method.train_summaries()" |
|
|
1496 |
] |
|
|
1497 |
}, |
|
|
1498 |
{ |
|
|
1499 |
"cell_type": "markdown", |
|
|
1500 |
"metadata": { |
|
|
1501 |
"deletable": true, |
|
|
1502 |
"editable": true |
|
|
1503 |
}, |
|
|
1504 |
"source": [ |
|
|
1505 |
"Fit Performance" |
|
|
1506 |
] |
|
|
1507 |
}, |
|
|
1508 |
{ |
|
|
1509 |
"cell_type": "code", |
|
|
1510 |
"execution_count": null, |
|
|
1511 |
"metadata": { |
|
|
1512 |
"collapsed": false, |
|
|
1513 |
"deletable": true, |
|
|
1514 |
"editable": true |
|
|
1515 |
}, |
|
|
1516 |
"outputs": [], |
|
|
1517 |
"source": [ |
|
|
1518 |
"o_summaries = dict()\n", |
|
|
1519 |
"model = charlson_training_method.predict(features_extra[\"train\"][charlson_features_names], \"train\")" |
|
|
1520 |
] |
|
|
1521 |
}, |
|
|
1522 |
{ |
|
|
1523 |
"cell_type": "code", |
|
|
1524 |
"execution_count": null, |
|
|
1525 |
"metadata": { |
|
|
1526 |
"collapsed": false, |
|
|
1527 |
"deletable": true, |
|
|
1528 |
"editable": true |
|
|
1529 |
}, |
|
|
1530 |
"outputs": [], |
|
|
1531 |
"source": [ |
|
|
1532 |
"# short summary\n", |
|
|
1533 |
"o_summaries = charlson_training_method.predict_summaries(pd.Series(features_extra[\"train\"][target_feature]), \"train\")\n", |
|
|
1534 |
"print(\"ROC AUC:\", o_summaries['roc_auc_score_1'], \"\\n\", o_summaries['classification_report'])\n", |
|
|
1535 |
"for k in o_summaries.keys():\n", |
|
|
1536 |
" print(k, o_summaries[k])" |
|
|
1537 |
] |
|
|
1538 |
}, |
|
|
1539 |
{ |
|
|
1540 |
"cell_type": "markdown", |
|
|
1541 |
"metadata": { |
|
|
1542 |
"deletable": true, |
|
|
1543 |
"editable": true |
|
|
1544 |
}, |
|
|
1545 |
"source": [ |
|
|
1546 |
"### 3.4. Predict" |
|
|
1547 |
] |
|
|
1548 |
}, |
|
|
1549 |
{ |
|
|
1550 |
"cell_type": "code", |
|
|
1551 |
"execution_count": null, |
|
|
1552 |
"metadata": { |
|
|
1553 |
"collapsed": false, |
|
|
1554 |
"deletable": true, |
|
|
1555 |
"editable": true |
|
|
1556 |
}, |
|
|
1557 |
"outputs": [], |
|
|
1558 |
"source": [ |
|
|
1559 |
"o_summaries = dict()\n", |
|
|
1560 |
"model = charlson_training_method.predict(features_extra[\"test\"][charlson_features_names], \"test\")" |
|
|
1561 |
] |
|
|
1562 |
}, |
|
|
1563 |
{ |
|
|
1564 |
"cell_type": "code", |
|
|
1565 |
"execution_count": null, |
|
|
1566 |
"metadata": { |
|
|
1567 |
"collapsed": false, |
|
|
1568 |
"deletable": true, |
|
|
1569 |
"editable": true |
|
|
1570 |
}, |
|
|
1571 |
"outputs": [], |
|
|
1572 |
"source": [ |
|
|
1573 |
"# short summary\n", |
|
|
1574 |
"o_summaries = charlson_training_method.predict_summaries(pd.Series(features_extra[\"test\"][target_feature]), \"test\")\n", |
|
|
1575 |
"print(\"ROC AUC:\", o_summaries['roc_auc_score_1'], \"\\n\", o_summaries['classification_report'])\n", |
|
|
1576 |
"for k in o_summaries.keys():\n", |
|
|
1577 |
" print(k, o_summaries[k])" |
|
|
1578 |
] |
|
|
1579 |
}, |
|
|
1580 |
{ |
|
|
1581 |
"cell_type": "markdown", |
|
|
1582 |
"metadata": { |
|
|
1583 |
"deletable": true, |
|
|
1584 |
"editable": true |
|
|
1585 |
}, |
|
|
1586 |
"source": [ |
|
|
1587 |
"### 3.5. Cross-Validate" |
|
|
1588 |
] |
|
|
1589 |
}, |
|
|
1590 |
{ |
|
|
1591 |
"cell_type": "code", |
|
|
1592 |
"execution_count": null, |
|
|
1593 |
"metadata": { |
|
|
1594 |
"collapsed": false, |
|
|
1595 |
"deletable": true, |
|
|
1596 |
"editable": true |
|
|
1597 |
}, |
|
|
1598 |
"outputs": [], |
|
|
1599 |
"source": [ |
|
|
1600 |
"o_summaries = dict()\n", |
|
|
1601 |
"score = charlson_training_method.cross_validate(features_extra[\"test\"][charlson_features_names], features_extra[\"test\"][target_feature], \n", |
|
|
1602 |
" scoring=\"neg_mean_squared_error\", cv=10)" |
|
|
1603 |
] |
|
|
1604 |
}, |
|
|
1605 |
{ |
|
|
1606 |
"cell_type": "code", |
|
|
1607 |
"execution_count": null, |
|
|
1608 |
"metadata": { |
|
|
1609 |
"collapsed": false, |
|
|
1610 |
"deletable": true, |
|
|
1611 |
"editable": true |
|
|
1612 |
}, |
|
|
1613 |
"outputs": [], |
|
|
1614 |
"source": [ |
|
|
1615 |
"# short summary\n", |
|
|
1616 |
"o_summaries = charlson_training_method.cross_validate_summaries()\n", |
|
|
1617 |
"print(\"Scores: \", o_summaries)" |
|
|
1618 |
] |
|
|
1619 |
}, |
|
|
1620 |
{ |
|
|
1621 |
"cell_type": "markdown", |
|
|
1622 |
"metadata": { |
|
|
1623 |
"deletable": true, |
|
|
1624 |
"editable": true |
|
|
1625 |
}, |
|
|
1626 |
"source": [ |
|
|
1627 |
"### 3.6. Save" |
|
|
1628 |
] |
|
|
1629 |
}, |
|
|
1630 |
{ |
|
|
1631 |
"cell_type": "code", |
|
|
1632 |
"execution_count": null, |
|
|
1633 |
"metadata": { |
|
|
1634 |
"collapsed": false, |
|
|
1635 |
"deletable": true, |
|
|
1636 |
"editable": true, |
|
|
1637 |
"scrolled": true |
|
|
1638 |
}, |
|
|
1639 |
"outputs": [], |
|
|
1640 |
"source": [ |
|
|
1641 |
"charlson_training_method.save_model(path=CONSTANTS.io_path, title=file_name)" |
|
|
1642 |
] |
|
|
1643 |
}, |
|
|
1644 |
{ |
|
|
1645 |
"cell_type": "markdown", |
|
|
1646 |
"metadata": { |
|
|
1647 |
"deletable": true, |
|
|
1648 |
"editable": true |
|
|
1649 |
}, |
|
|
1650 |
"source": [ |
|
|
1651 |
"<br/><br/>" |
|
|
1652 |
] |
|
|
1653 |
}, |
|
|
1654 |
{ |
|
|
1655 |
"cell_type": "markdown", |
|
|
1656 |
"metadata": { |
|
|
1657 |
"deletable": true, |
|
|
1658 |
"editable": true |
|
|
1659 |
}, |
|
|
1660 |
"source": [ |
|
|
1661 |
"## 4. Features Statistics" |
|
|
1662 |
] |
|
|
1663 |
}, |
|
|
1664 |
{ |
|
|
1665 |
"cell_type": "markdown", |
|
|
1666 |
"metadata": { |
|
|
1667 |
"collapsed": true, |
|
|
1668 |
"deletable": true, |
|
|
1669 |
"editable": true |
|
|
1670 |
}, |
|
|
1671 |
"source": [ |
|
|
1672 |
"### 4.1. Features Rank" |
|
|
1673 |
] |
|
|
1674 |
}, |
|
|
1675 |
{ |
|
|
1676 |
"cell_type": "markdown", |
|
|
1677 |
"metadata": { |
|
|
1678 |
"collapsed": false, |
|
|
1679 |
"deletable": true, |
|
|
1680 |
"editable": true |
|
|
1681 |
}, |
|
|
1682 |
"source": [ |
|
|
1683 |
"<i>It is produced during modelling</i>" |
|
|
1684 |
] |
|
|
1685 |
}, |
|
|
1686 |
{ |
|
|
1687 |
"cell_type": "markdown", |
|
|
1688 |
"metadata": { |
|
|
1689 |
"deletable": true, |
|
|
1690 |
"editable": true |
|
|
1691 |
}, |
|
|
1692 |
"source": [ |
|
|
1693 |
"### 4.2. Descriptive Statistics" |
|
|
1694 |
] |
|
|
1695 |
}, |
|
|
1696 |
{ |
|
|
1697 |
"cell_type": "markdown", |
|
|
1698 |
"metadata": { |
|
|
1699 |
"collapsed": false, |
|
|
1700 |
"deletable": true, |
|
|
1701 |
"editable": true |
|
|
1702 |
}, |
|
|
1703 |
"source": [ |
|
|
1704 |
"<i>It is produced during modelling</i>" |
|
|
1705 |
] |
|
|
1706 |
}, |
|
|
1707 |
{ |
|
|
1708 |
"cell_type": "markdown", |
|
|
1709 |
"metadata": { |
|
|
1710 |
"deletable": true, |
|
|
1711 |
"editable": true |
|
|
1712 |
}, |
|
|
1713 |
"source": [ |
|
|
1714 |
"### 4.3. Features Weigths" |
|
|
1715 |
] |
|
|
1716 |
}, |
|
|
1717 |
{ |
|
|
1718 |
"cell_type": "code", |
|
|
1719 |
"execution_count": null, |
|
|
1720 |
"metadata": { |
|
|
1721 |
"collapsed": false, |
|
|
1722 |
"deletable": true, |
|
|
1723 |
"editable": true |
|
|
1724 |
}, |
|
|
1725 |
"outputs": [], |
|
|
1726 |
"source": [ |
|
|
1727 |
"def features_importance_rank(fitting_method, ranking_file_name=None, rank_models=[\"rfc\", \"gbrt\", \"randLogit\"]):\n", |
|
|
1728 |
" # Fitting weight\n", |
|
|
1729 |
" o_summaries = pd.DataFrame({\"Name\": fitting_method.model_labels,\n", |
|
|
1730 |
" \"Fitting Weight\": fitting_method.train_summaries()[\"feature_importances_\"]},\n", |
|
|
1731 |
" index = fitting_method.model_labels)\n", |
|
|
1732 |
" o_summaries = o_summaries.sort_values(\"Fitting Weight\", ascending=False)\n", |
|
|
1733 |
" o_summaries = o_summaries.reset_index(drop=True)\n", |
|
|
1734 |
" \n", |
|
|
1735 |
" # Ranking scores\n", |
|
|
1736 |
" if ranking_file_name is not None:\n", |
|
|
1737 |
" for rank_model in rank_models:\n", |
|
|
1738 |
" o_summaries_ranks = readers_writers.load_serialised_compressed(\n", |
|
|
1739 |
" path=CONSTANTS.io_path, title=ranking_file_name + rank_model)\n", |
|
|
1740 |
" for trial in range(len(o_summaries_ranks)):\n", |
|
|
1741 |
" o_summaries_rank = pd.DataFrame(o_summaries_ranks[trial])\n", |
|
|
1742 |
" o_summaries_rank.columns = [\"Name\", \"Importance - \" + rank_model + \" - Trial_\" + str(trial),\n", |
|
|
1743 |
" \"Order - \" + rank_model + \" - Trial_\" + str(trial)]\n", |
|
|
1744 |
" o_summaries = o_summaries.merge(o_summaries_rank, how=\"outer\", on=\"Name\")\n", |
|
|
1745 |
" \n", |
|
|
1746 |
" return o_summaries" |
|
|
1747 |
] |
|
|
1748 |
}, |
|
|
1749 |
{ |
|
|
1750 |
"cell_type": "code", |
|
|
1751 |
"execution_count": null, |
|
|
1752 |
"metadata": { |
|
|
1753 |
"collapsed": false, |
|
|
1754 |
"deletable": true, |
|
|
1755 |
"editable": true |
|
|
1756 |
}, |
|
|
1757 |
"outputs": [], |
|
|
1758 |
"source": [ |
|
|
1759 |
"file_name = \"Step_07_Model_Train_model_rank_summaries_\"\n", |
|
|
1760 |
"\n", |
|
|
1761 |
"o_summaries = features_importance_rank(fitting_method=training_method, ranking_file_name=file_name, rank_models=rank_models)\n", |
|
|
1762 |
"\n", |
|
|
1763 |
"file_name = \"report_weights_ranks\"\n", |
|
|
1764 |
"readers_writers.save_csv(path=CONSTANTS.io_path, title=file_name, data=o_summaries, append=False, extension=\"csv\", header=o_summaries.columns)\n", |
|
|
1765 |
"\n", |
|
|
1766 |
"display(o_summaries.head())" |
|
|
1767 |
] |
|
|
1768 |
}, |
|
|
1769 |
{ |
|
|
1770 |
"cell_type": "markdown", |
|
|
1771 |
"metadata": { |
|
|
1772 |
"deletable": true, |
|
|
1773 |
"editable": true |
|
|
1774 |
}, |
|
|
1775 |
"source": [ |
|
|
1776 |
"<br/><br/>" |
|
|
1777 |
] |
|
|
1778 |
}, |
|
|
1779 |
{ |
|
|
1780 |
"cell_type": "markdown", |
|
|
1781 |
"metadata": { |
|
|
1782 |
"deletable": true, |
|
|
1783 |
"editable": true |
|
|
1784 |
}, |
|
|
1785 |
"source": [ |
|
|
1786 |
"## 5. Model Performance" |
|
|
1787 |
] |
|
|
1788 |
}, |
|
|
1789 |
{ |
|
|
1790 |
"cell_type": "markdown", |
|
|
1791 |
"metadata": { |
|
|
1792 |
"deletable": true, |
|
|
1793 |
"editable": true |
|
|
1794 |
}, |
|
|
1795 |
"source": [ |
|
|
1796 |
"### 5.1. Performance Indicators" |
|
|
1797 |
] |
|
|
1798 |
}, |
|
|
1799 |
{ |
|
|
1800 |
"cell_type": "code", |
|
|
1801 |
"execution_count": null, |
|
|
1802 |
"metadata": { |
|
|
1803 |
"collapsed": true, |
|
|
1804 |
"deletable": true, |
|
|
1805 |
"editable": true |
|
|
1806 |
}, |
|
|
1807 |
"outputs": [], |
|
|
1808 |
"source": [ |
|
|
1809 |
"measures = [\"accuracy_score\", \"precision_score\", \"recall_score\",\n", |
|
|
1810 |
" \"roc_auc_score_1\", \"f1_score\", \"fbeta_score\", \"average_precision_score\", \n", |
|
|
1811 |
" \"log_loss\", \"zero_one_loss\", \"hamming_loss\", \"jaccard_similarity_score\", \"matthews_corrcoef\"]" |
|
|
1812 |
] |
|
|
1813 |
}, |
|
|
1814 |
{ |
|
|
1815 |
"cell_type": "code", |
|
|
1816 |
"execution_count": null, |
|
|
1817 |
"metadata": { |
|
|
1818 |
"collapsed": false, |
|
|
1819 |
"deletable": true, |
|
|
1820 |
"editable": true |
|
|
1821 |
}, |
|
|
1822 |
"outputs": [], |
|
|
1823 |
"source": [ |
|
|
1824 |
"# train\n", |
|
|
1825 |
"o_summaries = training_method.predict_summaries(features_extra[\"train\"][target_feature], \"train\")\n", |
|
|
1826 |
"o_summaries = np.array([(m, o_summaries[m]) for m in measures])\n", |
|
|
1827 |
"report_performance = pd.DataFrame({\"Measure\": o_summaries[:, 0], \n", |
|
|
1828 |
" \"Sample Train\": o_summaries[:, 1], \n", |
|
|
1829 |
" \"Sample Test\": [None] * len(measures)})\n", |
|
|
1830 |
"\n", |
|
|
1831 |
"# test\n", |
|
|
1832 |
"o_summaries = training_method.predict_summaries(features_extra[\"test\"][target_feature], \"test\")\n", |
|
|
1833 |
"o_summaries = np.array([(m, o_summaries[m]) for m in measures])\n", |
|
|
1834 |
"report_performance[\"Sample Test\"] = o_summaries[:, 1]" |
|
|
1835 |
] |
|
|
1836 |
}, |
|
|
1837 |
{ |
|
|
1838 |
"cell_type": "code", |
|
|
1839 |
"execution_count": null, |
|
|
1840 |
"metadata": { |
|
|
1841 |
"collapsed": false, |
|
|
1842 |
"deletable": true, |
|
|
1843 |
"editable": true, |
|
|
1844 |
"scrolled": true |
|
|
1845 |
}, |
|
|
1846 |
"outputs": [], |
|
|
1847 |
"source": [ |
|
|
1848 |
"# print\n", |
|
|
1849 |
"file_name = \"report_performance_\" + method_name + \"_\" + target_feature\n", |
|
|
1850 |
"display(report_performance)\n", |
|
|
1851 |
"readers_writers.save_csv(path=CONSTANTS.io_path, title=file_name, data=report_performance, append=False)" |
|
|
1852 |
] |
|
|
1853 |
}, |
|
|
1854 |
{ |
|
|
1855 |
"cell_type": "markdown", |
|
|
1856 |
"metadata": { |
|
|
1857 |
"deletable": true, |
|
|
1858 |
"editable": true |
|
|
1859 |
}, |
|
|
1860 |
"source": [ |
|
|
1861 |
"### 5.2. Population Statistics" |
|
|
1862 |
] |
|
|
1863 |
}, |
|
|
1864 |
{ |
|
|
1865 |
"cell_type": "code", |
|
|
1866 |
"execution_count": null, |
|
|
1867 |
"metadata": { |
|
|
1868 |
"collapsed": false, |
|
|
1869 |
"deletable": true, |
|
|
1870 |
"editable": true |
|
|
1871 |
}, |
|
|
1872 |
"outputs": [], |
|
|
1873 |
"source": [ |
|
|
1874 |
"def population_statistics(df, diagnoses, cutpoints=[0.50, 0.60, 0.70, 0.80, 0.90]):\n", |
|
|
1875 |
" o_summaries = pd.DataFrame(columns=['Name'], index=diagnoses)\n", |
|
|
1876 |
" o_summaries['Name'] = diagnoses\n", |
|
|
1877 |
" \n", |
|
|
1878 |
" for diagnose in diagnoses:\n", |
|
|
1879 |
" o_summaries.loc[diagnose, 'Total'] = len(df.index)\n", |
|
|
1880 |
" if diagnose not in df:\n", |
|
|
1881 |
" continue\n", |
|
|
1882 |
" \n", |
|
|
1883 |
" o_summaries.loc[diagnose, 'Total - diagnose'] = len(df.loc[(df[diagnose] > 0)].index)\n", |
|
|
1884 |
" o_summaries.loc[diagnose, 'Total - diagnose - label_1'] = len(df.loc[(df[diagnose] > 0) & (df[target_feature] > 0)].index)\n", |
|
|
1885 |
" o_summaries.loc[diagnose, 'Emergency Readmission Rate - cnt 1'] = len(df.loc[(df[diagnose] > 0) & (df['admimeth_0t30d_prevalence_1_cnt'] > 0) & (df[target_feature] > 0)].index)\n", |
|
|
1886 |
" o_summaries.loc[diagnose, 'Emergency Readmission Rate - cnt 2'] = len(df.loc[(df[diagnose] > 0) & (df['admimeth_0t30d_prevalence_2_cnt'] > 0) & (df[target_feature] > 0)].index)\n", |
|
|
1887 |
" o_summaries.loc[diagnose, 'Emergency Readmission Rate - cnt 3'] = len(df.loc[(df[diagnose] > 0) & (df['admimeth_0t30d_prevalence_3_cnt'] > 0) & (df[target_feature] > 0)].index)\n", |
|
|
1888 |
" o_summaries.loc[diagnose, 'Prior Spells'] = len(df.loc[(df[diagnose] > 0) & (df['prior_spells'] > 0) & (df[target_feature] > 0)].index)\n", |
|
|
1889 |
" o_summaries.loc[diagnose, 'Male - perc'] = len(df.loc[(df[diagnose] > 0) & (df['gender_1'] > 0) & (df[target_feature] > 0)].index)\n", |
|
|
1890 |
" age = df.loc[(df[diagnose] > 0) & (df[target_feature] > 0)]['trigger_age'].describe(percentiles=[.25, .5, .75])\n", |
|
|
1891 |
" o_summaries.loc[diagnose, 'Age - IQR_min'] = age['min']\n", |
|
|
1892 |
" o_summaries.loc[diagnose, 'Age - IQR_25'] = age['25%']\n", |
|
|
1893 |
" o_summaries.loc[diagnose, 'Age - IQR_50'] = age['50%']\n", |
|
|
1894 |
" o_summaries.loc[diagnose, 'Age - IQR_75'] = age['75%']\n", |
|
|
1895 |
" o_summaries.loc[diagnose, 'Age - IQR_max'] = age['max']\n", |
|
|
1896 |
" los = df.loc[(df[diagnose] > 0) & (df[target_feature] > 0)]['trigger_los'].describe(percentiles=[.25, .5, .75])\n", |
|
|
1897 |
" o_summaries.loc[diagnose, 'LoS - IQR_min'] = los['min']\n", |
|
|
1898 |
" o_summaries.loc[diagnose, 'LoS - IQR_25'] = los['25%']\n", |
|
|
1899 |
" o_summaries.loc[diagnose, 'LoS - IQR_50'] = los['50%']\n", |
|
|
1900 |
" o_summaries.loc[diagnose, 'LoS - IQR_75'] = los['75%']\n", |
|
|
1901 |
" o_summaries.loc[diagnose, 'LoS - IQR_max'] = los['max']\n", |
|
|
1902 |
" for cutpoint in cutpoints:\n", |
|
|
1903 |
" o_summaries.loc[diagnose, 'score - ' + str(cutpoint)] = len(df.loc[(df[diagnose] > 0) & (df['score'] > cutpoint)].index)\n", |
|
|
1904 |
" o_summaries.loc[diagnose, 'TP - ' + str(cutpoint)] = len(df.loc[(df[diagnose] > 0) & (df[target_feature] > 0) & (df['score'] > cutpoint)].index)\n", |
|
|
1905 |
" o_summaries.loc[diagnose, 'FP - ' + str(cutpoint)] = len(df.loc[(df[diagnose] > 0) & (df[target_feature] == 0) & (df['score'] > cutpoint)].index)\n", |
|
|
1906 |
" o_summaries.loc[diagnose, 'FN - ' + str(cutpoint)] = len(df.loc[(df[diagnose] > 0) & (df[target_feature] > 0) & (df['score'] <= cutpoint)].index)\n", |
|
|
1907 |
" o_summaries.loc[diagnose, 'TN - ' + str(cutpoint)] = len(df.loc[(df[diagnose] > 0) & (df[target_feature] == 0) & (df['score'] <= cutpoint)].index)\n", |
|
|
1908 |
" \n", |
|
|
1909 |
" \n", |
|
|
1910 |
" o_summaries.loc[diagnose, 'Charlson - 0'] = len(df.loc[(df[diagnose] > 0) & (df[\"trigger_charlsonFoster\"] == 0)].index)\n", |
|
|
1911 |
" o_summaries.loc[diagnose, 'Charlson - 0 - label_1'] = len(df.loc[(df[diagnose] > 0) & (df[\"trigger_charlsonFoster\"] == 0) & (df[target_feature] > 0)].index)\n", |
|
|
1912 |
" o_summaries.loc[diagnose, 'Charlson - 1'] = len(df.loc[(df[diagnose] > 0) & (df[\"trigger_charlsonFoster\"] == 1)].index)\n", |
|
|
1913 |
" o_summaries.loc[diagnose, 'Charlson - 1 - label_1'] = len(df.loc[(df[diagnose] > 0) & (df[\"trigger_charlsonFoster\"] == 1) & (df[target_feature] > 0)].index)\n", |
|
|
1914 |
" o_summaries.loc[diagnose, 'Charlson - 2'] = len(df.loc[(df[diagnose] > 0) & (df[\"trigger_charlsonFoster\"] == 2)].index)\n", |
|
|
1915 |
" o_summaries.loc[diagnose, 'Charlson - 2 - label_1'] = len(df.loc[(df[diagnose] > 0) & (df[\"trigger_charlsonFoster\"] == 2) & (df[target_feature] > 0)].index)\n", |
|
|
1916 |
" o_summaries.loc[diagnose, 'Charlson - 3'] = len(df.loc[(df[diagnose] > 0) & (df[\"trigger_charlsonFoster\"] == 3)].index)\n", |
|
|
1917 |
" o_summaries.loc[diagnose, 'Charlson - 3 - label_1'] = len(df.loc[(df[diagnose] > 0) & (df[\"trigger_charlsonFoster\"] == 3) & (df[target_feature] > 0)].index)\n", |
|
|
1918 |
" o_summaries.loc[diagnose, 'Charlson - 4+'] = len(df.loc[(df[diagnose] > 0) & (df[\"trigger_charlsonFoster\"] >= 4)].index)\n", |
|
|
1919 |
" o_summaries.loc[diagnose, 'Charlson - 4+ - label_1'] = len(df.loc[(df[diagnose] > 0) & (df[\"trigger_charlsonFoster\"] >= 4) & (df[target_feature] > 0)].index)\n", |
|
|
1920 |
" \n", |
|
|
1921 |
" for cutpoint in cutpoints:\n", |
|
|
1922 |
" o_summaries.loc[diagnose, 'Charlson - 0 - label_1 - TP - ' + str(cutpoint)] = \\\n", |
|
|
1923 |
" len(df.loc[(df[diagnose] > 0) & (df[\"trigger_charlsonFoster\"] == 0) & (df[target_feature] > 0) & (df['score'] > cutpoint)].index)\n", |
|
|
1924 |
" \n", |
|
|
1925 |
" return o_summaries" |
|
|
1926 |
] |
|
|
1927 |
}, |
|
|
1928 |
{ |
|
|
1929 |
"cell_type": "markdown", |
|
|
1930 |
"metadata": { |
|
|
1931 |
"deletable": true, |
|
|
1932 |
"editable": true |
|
|
1933 |
}, |
|
|
1934 |
"source": [ |
|
|
1935 |
"#### 5.2.1. Most Prevalent Diagnoses Groups\n", |
|
|
1936 |
"Most prevalent diagnoses groups (30-day, 1-year readmission): \n", |
|
|
1937 |
"* Total, Admissions, Emergency Readmission Rate, Prior Spells, Male (%), Age (IQR), LoS (IQR), TP, FP, FN, TN" |
|
|
1938 |
] |
|
|
1939 |
}, |
|
|
1940 |
{ |
|
|
1941 |
"cell_type": "code", |
|
|
1942 |
"execution_count": null, |
|
|
1943 |
"metadata": { |
|
|
1944 |
"collapsed": true, |
|
|
1945 |
"deletable": true, |
|
|
1946 |
"editable": true |
|
|
1947 |
}, |
|
|
1948 |
"outputs": [], |
|
|
1949 |
"source": [ |
|
|
1950 |
"diagnoses = ['diagCCS_0t30d_others_cnt', 'diagCCS_0t30d_prevalence_1_cnt', 'diagCCS_0t30d_prevalence_2_cnt', 'diagCCS_0t30d_prevalence_3_cnt', 'diagCCS_0t30d_prevalence_4_cnt', 'diagCCS_0t30d_prevalence_5_cnt', 'diagCCS_0t30d_prevalence_6_cnt', 'diagCCS_0t30d_prevalence_7_cnt', 'diagCCS_0t30d_prevalence_8_cnt', 'diagCCS_0t30d_prevalence_9_cnt', 'diagCCS_0t30d_prevalence_10_cnt', 'diagCCS_0t30d_prevalence_11_cnt', 'diagCCS_0t30d_prevalence_12_cnt', 'diagCCS_0t30d_prevalence_13_cnt', 'diagCCS_0t30d_prevalence_14_cnt', 'diagCCS_0t30d_prevalence_15_cnt', 'diagCCS_0t30d_prevalence_16_cnt', 'diagCCS_0t30d_prevalence_17_cnt', 'diagCCS_0t30d_prevalence_18_cnt', 'diagCCS_0t30d_prevalence_19_cnt', 'diagCCS_0t30d_prevalence_20_cnt', 'diagCCS_0t30d_prevalence_21_cnt', 'diagCCS_0t30d_prevalence_22_cnt', 'diagCCS_0t30d_prevalence_23_cnt', 'diagCCS_0t30d_prevalence_24_cnt', 'diagCCS_0t30d_prevalence_25_cnt', 'diagCCS_0t30d_prevalence_26_cnt', 'diagCCS_0t30d_prevalence_27_cnt', 'diagCCS_0t30d_prevalence_28_cnt', 'diagCCS_0t30d_prevalence_29_cnt', 'diagCCS_0t30d_prevalence_30_cnt'\n", |
|
|
1951 |
" , 'diagCCS_30t90d_others_cnt', 'diagCCS_30t90d_prevalence_1_cnt', 'diagCCS_30t90d_prevalence_2_cnt', 'diagCCS_30t90d_prevalence_3_cnt', 'diagCCS_30t90d_prevalence_4_cnt', 'diagCCS_30t90d_prevalence_5_cnt', 'diagCCS_30t90d_prevalence_6_cnt', 'diagCCS_30t90d_prevalence_7_cnt', 'diagCCS_30t90d_prevalence_8_cnt', 'diagCCS_30t90d_prevalence_9_cnt', 'diagCCS_30t90d_prevalence_10_cnt', 'diagCCS_30t90d_prevalence_11_cnt', 'diagCCS_30t90d_prevalence_12_cnt', 'diagCCS_30t90d_prevalence_13_cnt', 'diagCCS_30t90d_prevalence_14_cnt', 'diagCCS_30t90d_prevalence_15_cnt', 'diagCCS_30t90d_prevalence_16_cnt', 'diagCCS_30t90d_prevalence_17_cnt', 'diagCCS_30t90d_prevalence_18_cnt', 'diagCCS_30t90d_prevalence_19_cnt', 'diagCCS_30t90d_prevalence_20_cnt', 'diagCCS_30t90d_prevalence_21_cnt', 'diagCCS_30t90d_prevalence_22_cnt', 'diagCCS_30t90d_prevalence_23_cnt', 'diagCCS_30t90d_prevalence_24_cnt', 'diagCCS_30t90d_prevalence_25_cnt', 'diagCCS_30t90d_prevalence_26_cnt', 'diagCCS_30t90d_prevalence_27_cnt', 'diagCCS_30t90d_prevalence_28_cnt', 'diagCCS_30t90d_prevalence_29_cnt', 'diagCCS_30t90d_prevalence_30_cnt'\n", |
|
|
1952 |
" , 'diagCCS_90t180d_others_cnt', 'diagCCS_90t180d_prevalence_1_cnt', 'diagCCS_90t180d_prevalence_2_cnt', 'diagCCS_90t180d_prevalence_3_cnt', 'diagCCS_90t180d_prevalence_4_cnt', 'diagCCS_90t180d_prevalence_5_cnt', 'diagCCS_90t180d_prevalence_6_cnt', 'diagCCS_90t180d_prevalence_7_cnt', 'diagCCS_90t180d_prevalence_8_cnt', 'diagCCS_90t180d_prevalence_9_cnt', 'diagCCS_90t180d_prevalence_10_cnt', 'diagCCS_90t180d_prevalence_11_cnt', 'diagCCS_90t180d_prevalence_12_cnt', 'diagCCS_90t180d_prevalence_13_cnt', 'diagCCS_90t180d_prevalence_14_cnt', 'diagCCS_90t180d_prevalence_15_cnt', 'diagCCS_90t180d_prevalence_16_cnt', 'diagCCS_90t180d_prevalence_17_cnt', 'diagCCS_90t180d_prevalence_18_cnt', 'diagCCS_90t180d_prevalence_19_cnt', 'diagCCS_90t180d_prevalence_20_cnt', 'diagCCS_90t180d_prevalence_21_cnt', 'diagCCS_90t180d_prevalence_22_cnt', 'diagCCS_90t180d_prevalence_23_cnt', 'diagCCS_90t180d_prevalence_24_cnt', 'diagCCS_90t180d_prevalence_25_cnt', 'diagCCS_90t180d_prevalence_26_cnt', 'diagCCS_90t180d_prevalence_27_cnt', 'diagCCS_90t180d_prevalence_28_cnt', 'diagCCS_90t180d_prevalence_29_cnt', 'diagCCS_90t180d_prevalence_30_cnt'\n", |
|
|
1953 |
" , 'diagCCS_180t365d_others_cnt', 'diagCCS_180t365d_prevalence_1_cnt', 'diagCCS_180t365d_prevalence_2_cnt', 'diagCCS_180t365d_prevalence_3_cnt', 'diagCCS_180t365d_prevalence_4_cnt', 'diagCCS_180t365d_prevalence_5_cnt', 'diagCCS_180t365d_prevalence_6_cnt', 'diagCCS_180t365d_prevalence_7_cnt', 'diagCCS_180t365d_prevalence_8_cnt', 'diagCCS_180t365d_prevalence_9_cnt', 'diagCCS_180t365d_prevalence_10_cnt', 'diagCCS_180t365d_prevalence_11_cnt', 'diagCCS_180t365d_prevalence_12_cnt', 'diagCCS_180t365d_prevalence_13_cnt', 'diagCCS_180t365d_prevalence_14_cnt', 'diagCCS_180t365d_prevalence_15_cnt', 'diagCCS_180t365d_prevalence_16_cnt', 'diagCCS_180t365d_prevalence_17_cnt', 'diagCCS_180t365d_prevalence_18_cnt', 'diagCCS_180t365d_prevalence_19_cnt', 'diagCCS_180t365d_prevalence_20_cnt', 'diagCCS_180t365d_prevalence_21_cnt', 'diagCCS_180t365d_prevalence_22_cnt', 'diagCCS_180t365d_prevalence_23_cnt', 'diagCCS_180t365d_prevalence_24_cnt', 'diagCCS_180t365d_prevalence_25_cnt', 'diagCCS_180t365d_prevalence_26_cnt', 'diagCCS_180t365d_prevalence_27_cnt', 'diagCCS_180t365d_prevalence_28_cnt', 'diagCCS_180t365d_prevalence_29_cnt', 'diagCCS_180t365d_prevalence_30_cnt'\n", |
|
|
1954 |
" , 'diagCCS_365t730d_others_cnt', 'diagCCS_365t730d_prevalence_1_cnt', 'diagCCS_365t730d_prevalence_2_cnt', 'diagCCS_365t730d_prevalence_3_cnt', 'diagCCS_365t730d_prevalence_4_cnt', 'diagCCS_365t730d_prevalence_5_cnt', 'diagCCS_365t730d_prevalence_6_cnt', 'diagCCS_365t730d_prevalence_7_cnt', 'diagCCS_365t730d_prevalence_8_cnt', 'diagCCS_365t730d_prevalence_9_cnt', 'diagCCS_365t730d_prevalence_10_cnt', 'diagCCS_365t730d_prevalence_11_cnt', 'diagCCS_365t730d_prevalence_12_cnt', 'diagCCS_365t730d_prevalence_13_cnt', 'diagCCS_365t730d_prevalence_14_cnt', 'diagCCS_365t730d_prevalence_15_cnt', 'diagCCS_365t730d_prevalence_16_cnt', 'diagCCS_365t730d_prevalence_17_cnt', 'diagCCS_365t730d_prevalence_18_cnt', 'diagCCS_365t730d_prevalence_19_cnt', 'diagCCS_365t730d_prevalence_20_cnt', 'diagCCS_365t730d_prevalence_21_cnt', 'diagCCS_365t730d_prevalence_22_cnt', 'diagCCS_365t730d_prevalence_23_cnt', 'diagCCS_365t730d_prevalence_24_cnt', 'diagCCS_365t730d_prevalence_25_cnt', 'diagCCS_365t730d_prevalence_26_cnt', 'diagCCS_365t730d_prevalence_27_cnt', 'diagCCS_365t730d_prevalence_28_cnt', 'diagCCS_365t730d_prevalence_29_cnt', 'diagCCS_365t730d_prevalence_30_cnt']\n", |
|
|
1955 |
"file_name = \"report_population_prevalent_diagnoses_\" + method_name + \"_\" + target_feature + \"_\"" |
|
|
1956 |
] |
|
|
1957 |
}, |
|
|
1958 |
{ |
|
|
1959 |
"cell_type": "code", |
|
|
1960 |
"execution_count": null, |
|
|
1961 |
"metadata": { |
|
|
1962 |
"collapsed": false, |
|
|
1963 |
"deletable": true, |
|
|
1964 |
"editable": true |
|
|
1965 |
}, |
|
|
1966 |
"outputs": [], |
|
|
1967 |
"source": [ |
|
|
1968 |
"o_summaries = population_statistics(features_extra['train'], diagnoses)\n", |
|
|
1969 |
"readers_writers.save_csv(path=CONSTANTS.io_path, title=file_name + \"train\", data=o_summaries, append=False, extension=\"csv\", header=o_summaries.columns)\n", |
|
|
1970 |
"\n", |
|
|
1971 |
"o_summaries = population_statistics(features_extra['test'], diagnoses)\n", |
|
|
1972 |
"readers_writers.save_csv(path=CONSTANTS.io_path, title=file_name + \"test\", data=o_summaries, append=False, extension=\"csv\", header=o_summaries.columns)" |
|
|
1973 |
] |
|
|
1974 |
}, |
|
|
1975 |
{ |
|
|
1976 |
"cell_type": "markdown", |
|
|
1977 |
"metadata": { |
|
|
1978 |
"deletable": true, |
|
|
1979 |
"editable": true |
|
|
1980 |
}, |
|
|
1981 |
"source": [ |
|
|
1982 |
"#### 5.2.2. Major Comorbidity Groups\n", |
|
|
1983 |
"Comorbidity diagnoses groups (30-day, 1-year readmission): \n", |
|
|
1984 |
"* Total, Admissions, Emergency Readmission Rate, Prior Spells, Male (%), Age (IQR), LoS (IQR), TP, FP, FN, TN" |
|
|
1985 |
] |
|
|
1986 |
}, |
|
|
1987 |
{ |
|
|
1988 |
"cell_type": "code", |
|
|
1989 |
"execution_count": null, |
|
|
1990 |
"metadata": { |
|
|
1991 |
"collapsed": false, |
|
|
1992 |
"deletable": true, |
|
|
1993 |
"editable": true |
|
|
1994 |
}, |
|
|
1995 |
"outputs": [], |
|
|
1996 |
"source": [ |
|
|
1997 |
"diagnoses = ['prior_admiOther', 'prior_admiAcute', 'prior_spells', 'prior_asthma', 'prior_copd', 'prior_depression', 'prior_diabetes', 'prior_hypertension', 'prior_cancer', 'prior_chd', 'prior_chf']\n", |
|
|
1998 |
"file_name = \"report_population_comorbidity_diagnoses_\" + method_name + \"_\" + target_feature + \"_\"" |
|
|
1999 |
] |
|
|
2000 |
}, |
|
|
2001 |
{ |
|
|
2002 |
"cell_type": "code", |
|
|
2003 |
"execution_count": null, |
|
|
2004 |
"metadata": { |
|
|
2005 |
"collapsed": false, |
|
|
2006 |
"deletable": true, |
|
|
2007 |
"editable": true |
|
|
2008 |
}, |
|
|
2009 |
"outputs": [], |
|
|
2010 |
"source": [ |
|
|
2011 |
"o_summaries = population_statistics(features_extra['train'], diagnoses)\n", |
|
|
2012 |
"readers_writers.save_csv(path=CONSTANTS.io_path, title=file_name + \"train\", data=o_summaries, append=False, extension=\"csv\", header=o_summaries.columns)\n", |
|
|
2013 |
"\n", |
|
|
2014 |
"o_summaries = population_statistics(features_extra['test'], diagnoses)\n", |
|
|
2015 |
"readers_writers.save_csv(path=CONSTANTS.io_path, title=file_name + \"test\", data=o_summaries, append=False, extension=\"csv\", header=o_summaries.columns)" |
|
|
2016 |
] |
|
|
2017 |
}, |
|
|
2018 |
{ |
|
|
2019 |
"cell_type": "markdown", |
|
|
2020 |
"metadata": { |
|
|
2021 |
"deletable": true, |
|
|
2022 |
"editable": true |
|
|
2023 |
}, |
|
|
2024 |
"source": [ |
|
|
2025 |
"#### 5.2.3. Charlson Comorbidity Groups\n", |
|
|
2026 |
"Charlson diagnoses groups (30-day, 1-year readmission): \n", |
|
|
2027 |
"* Total, Admissions, Emergency Readmission Rate, Prior Spells, Male (%), Age (IQR), LoS (IQR), TP, FP, FN, TN" |
|
|
2028 |
] |
|
|
2029 |
}, |
|
|
2030 |
{ |
|
|
2031 |
"cell_type": "code", |
|
|
2032 |
"execution_count": null, |
|
|
2033 |
"metadata": { |
|
|
2034 |
"collapsed": true, |
|
|
2035 |
"deletable": true, |
|
|
2036 |
"editable": true |
|
|
2037 |
}, |
|
|
2038 |
"outputs": [], |
|
|
2039 |
"source": [ |
|
|
2040 |
"diagnoses = ['diagCci_01_myocardial_freq', 'diagCci_02_chf_freq', 'diagCci_03_pvd_freq', 'diagCci_04_cerebrovascular_freq', 'diagCci_05_dementia_freq', 'diagCci_06_cpd_freq', 'diagCci_07_rheumatic_freq', 'diagCci_08_ulcer_freq', 'diagCci_09_liverMild_freq', 'diagCci_10_diabetesNotChronic_freq', 'diagCci_11_diabetesChronic_freq', 'diagCci_12_hemiplegia_freq', 'diagCci_13_renal_freq', 'diagCci_14_malignancy_freq', 'diagCci_15_liverSevere_freq', 'diagCci_16_tumorSec_freq', 'diagCci_17_aids_freq', 'diagCci_18_depression_freq', 'diagCci_19_cardiac_freq', 'diagCci_20_valvular_freq', 'diagCci_21_pulmonary_freq', 'diagCci_22_vascular_freq', 'diagCci_23_hypertensionNotComplicated_freq', 'diagCci_24_hypertensionComplicated_freq', 'diagCci_25_paralysis_freq', 'diagCci_26_neuroOther_freq', 'diagCci_27_pulmonaryChronic_freq', 'diagCci_28_diabetesNotComplicated_freq', 'diagCci_29_diabetesComplicated_freq', 'diagCci_30_hypothyroidism_freq', 'diagCci_31_renal_freq', 'diagCci_32_liver_freq', 'diagCci_33_ulcerNotBleeding_freq', 'diagCci_34_psychoses_freq', 'diagCci_35_lymphoma_freq', 'diagCci_36_cancerSec_freq', 'diagCci_37_tumorNotSec_freq', 'diagCci_38_rheumatoid_freq', 'diagCci_39_coagulopathy_freq', 'diagCci_40_obesity_freq', 'diagCci_41_weightLoss_freq', 'diagCci_42_fluidDisorder_freq', 'diagCci_43_bloodLoss_freq', 'diagCci_44_anemia_freq', 'diagCci_45_alcohol_freq', 'diagCci_46_drug_freq']\n", |
|
|
2041 |
"file_name = \"report_population_charlson_diagnoses_\" + method_name + \"_\" + target_feature + \"_\"" |
|
|
2042 |
] |
|
|
2043 |
}, |
|
|
2044 |
{ |
|
|
2045 |
"cell_type": "code", |
|
|
2046 |
"execution_count": null, |
|
|
2047 |
"metadata": { |
|
|
2048 |
"collapsed": false, |
|
|
2049 |
"deletable": true, |
|
|
2050 |
"editable": true |
|
|
2051 |
}, |
|
|
2052 |
"outputs": [], |
|
|
2053 |
"source": [ |
|
|
2054 |
"o_summaries = population_statistics(features_extra['train'], diagnoses)\n", |
|
|
2055 |
"readers_writers.save_csv(path=CONSTANTS.io_path, title=file_name + \"train\", data=o_summaries, append=False, extension=\"csv\", header=o_summaries.columns)\n", |
|
|
2056 |
"\n", |
|
|
2057 |
"o_summaries = population_statistics(features_extra['test'], diagnoses)\n", |
|
|
2058 |
"readers_writers.save_csv(path=CONSTANTS.io_path, title=file_name + \"test\", data=o_summaries, append=False, extension=\"csv\", header=o_summaries.columns)" |
|
|
2059 |
] |
|
|
2060 |
}, |
|
|
2061 |
{ |
|
|
2062 |
"cell_type": "markdown", |
|
|
2063 |
"metadata": { |
|
|
2064 |
"deletable": true, |
|
|
2065 |
"editable": true |
|
|
2066 |
}, |
|
|
2067 |
"source": [ |
|
|
2068 |
"#### 5.2.4. Most Prevalent Operatons\n", |
|
|
2069 |
"Most prevalent operations variables (30-day, 1-year readmission): \n", |
|
|
2070 |
"* Total, Admissions, Emergency Readmission Rate, Prior Spells, Male (%), Age (IQR), LoS (IQR), TP, FP, FN, TN" |
|
|
2071 |
] |
|
|
2072 |
}, |
|
|
2073 |
{ |
|
|
2074 |
"cell_type": "code", |
|
|
2075 |
"execution_count": null, |
|
|
2076 |
"metadata": { |
|
|
2077 |
"collapsed": true, |
|
|
2078 |
"deletable": true, |
|
|
2079 |
"editable": true |
|
|
2080 |
}, |
|
|
2081 |
"outputs": [], |
|
|
2082 |
"source": [ |
|
|
2083 |
"diagnoses = ['operOPCSL1_0t30d_others_cnt', 'operOPCSL1_0t30d_prevalence_1_cnt', 'operOPCSL1_0t30d_prevalence_2_cnt', 'operOPCSL1_0t30d_prevalence_3_cnt', 'operOPCSL1_0t30d_prevalence_4_cnt', 'operOPCSL1_0t30d_prevalence_5_cnt', 'operOPCSL1_0t30d_prevalence_6_cnt', 'operOPCSL1_0t30d_prevalence_7_cnt', 'operOPCSL1_0t30d_prevalence_8_cnt', 'operOPCSL1_0t30d_prevalence_9_cnt', 'operOPCSL1_0t30d_prevalence_10_cnt', 'operOPCSL1_0t30d_prevalence_11_cnt', 'operOPCSL1_0t30d_prevalence_12_cnt', 'operOPCSL1_0t30d_prevalence_13_cnt', 'operOPCSL1_0t30d_prevalence_14_cnt', 'operOPCSL1_0t30d_prevalence_15_cnt', 'operOPCSL1_0t30d_prevalence_16_cnt', 'operOPCSL1_0t30d_prevalence_17_cnt', 'operOPCSL1_0t30d_prevalence_18_cnt', 'operOPCSL1_0t30d_prevalence_19_cnt', 'operOPCSL1_0t30d_prevalence_20_cnt', 'operOPCSL1_0t30d_prevalence_21_cnt', 'operOPCSL1_0t30d_prevalence_22_cnt', 'operOPCSL1_0t30d_prevalence_23_cnt', 'operOPCSL1_0t30d_prevalence_24_cnt', 'operOPCSL1_0t30d_prevalence_25_cnt', 'operOPCSL1_0t30d_prevalence_26_cnt', 'operOPCSL1_0t30d_prevalence_27_cnt', 'operOPCSL1_0t30d_prevalence_28_cnt', 'operOPCSL1_0t30d_prevalence_29_cnt', 'operOPCSL1_0t30d_prevalence_30_cnt'\n", |
|
|
2084 |
" , 'operOPCSL1_30t90d_others_cnt', 'operOPCSL1_30t90d_prevalence_1_cnt', 'operOPCSL1_30t90d_prevalence_2_cnt', 'operOPCSL1_30t90d_prevalence_3_cnt', 'operOPCSL1_30t90d_prevalence_4_cnt', 'operOPCSL1_30t90d_prevalence_5_cnt', 'operOPCSL1_30t90d_prevalence_6_cnt', 'operOPCSL1_30t90d_prevalence_7_cnt', 'operOPCSL1_30t90d_prevalence_8_cnt', 'operOPCSL1_30t90d_prevalence_9_cnt', 'operOPCSL1_30t90d_prevalence_10_cnt', 'operOPCSL1_30t90d_prevalence_11_cnt', 'operOPCSL1_30t90d_prevalence_12_cnt', 'operOPCSL1_30t90d_prevalence_13_cnt', 'operOPCSL1_30t90d_prevalence_14_cnt', 'operOPCSL1_30t90d_prevalence_15_cnt', 'operOPCSL1_30t90d_prevalence_16_cnt', 'operOPCSL1_30t90d_prevalence_17_cnt', 'operOPCSL1_30t90d_prevalence_18_cnt', 'operOPCSL1_30t90d_prevalence_19_cnt', 'operOPCSL1_30t90d_prevalence_20_cnt', 'operOPCSL1_30t90d_prevalence_21_cnt', 'operOPCSL1_30t90d_prevalence_22_cnt', 'operOPCSL1_30t90d_prevalence_23_cnt', 'operOPCSL1_30t90d_prevalence_24_cnt', 'operOPCSL1_30t90d_prevalence_25_cnt', 'operOPCSL1_30t90d_prevalence_26_cnt', 'operOPCSL1_30t90d_prevalence_27_cnt', 'operOPCSL1_30t90d_prevalence_28_cnt', 'operOPCSL1_30t90d_prevalence_29_cnt', 'operOPCSL1_30t90d_prevalence_30_cnt'\n", |
|
|
2085 |
" , 'operOPCSL1_90t180d_others_cnt', 'operOPCSL1_90t180d_prevalence_1_cnt', 'operOPCSL1_90t180d_prevalence_2_cnt', 'operOPCSL1_90t180d_prevalence_3_cnt', 'operOPCSL1_90t180d_prevalence_4_cnt', 'operOPCSL1_90t180d_prevalence_5_cnt', 'operOPCSL1_90t180d_prevalence_6_cnt', 'operOPCSL1_90t180d_prevalence_7_cnt', 'operOPCSL1_90t180d_prevalence_8_cnt', 'operOPCSL1_90t180d_prevalence_9_cnt', 'operOPCSL1_90t180d_prevalence_10_cnt', 'operOPCSL1_90t180d_prevalence_11_cnt', 'operOPCSL1_90t180d_prevalence_12_cnt', 'operOPCSL1_90t180d_prevalence_13_cnt', 'operOPCSL1_90t180d_prevalence_14_cnt', 'operOPCSL1_90t180d_prevalence_15_cnt', 'operOPCSL1_90t180d_prevalence_16_cnt', 'operOPCSL1_90t180d_prevalence_17_cnt', 'operOPCSL1_90t180d_prevalence_18_cnt', 'operOPCSL1_90t180d_prevalence_19_cnt', 'operOPCSL1_90t180d_prevalence_20_cnt', 'operOPCSL1_90t180d_prevalence_21_cnt', 'operOPCSL1_90t180d_prevalence_22_cnt', 'operOPCSL1_90t180d_prevalence_23_cnt', 'operOPCSL1_90t180d_prevalence_24_cnt', 'operOPCSL1_90t180d_prevalence_25_cnt', 'operOPCSL1_90t180d_prevalence_26_cnt', 'operOPCSL1_90t180d_prevalence_27_cnt', 'operOPCSL1_90t180d_prevalence_28_cnt', 'operOPCSL1_90t180d_prevalence_29_cnt', 'operOPCSL1_90t180d_prevalence_30_cnt'\n", |
|
|
2086 |
" , 'operOPCSL1_180t365d_others_cnt', 'operOPCSL1_180t365d_prevalence_1_cnt', 'operOPCSL1_180t365d_prevalence_2_cnt', 'operOPCSL1_180t365d_prevalence_3_cnt', 'operOPCSL1_180t365d_prevalence_4_cnt', 'operOPCSL1_180t365d_prevalence_5_cnt', 'operOPCSL1_180t365d_prevalence_6_cnt', 'operOPCSL1_180t365d_prevalence_7_cnt', 'operOPCSL1_180t365d_prevalence_8_cnt', 'operOPCSL1_180t365d_prevalence_9_cnt', 'operOPCSL1_180t365d_prevalence_10_cnt', 'operOPCSL1_180t365d_prevalence_11_cnt', 'operOPCSL1_180t365d_prevalence_12_cnt', 'operOPCSL1_180t365d_prevalence_13_cnt', 'operOPCSL1_180t365d_prevalence_14_cnt', 'operOPCSL1_180t365d_prevalence_15_cnt', 'operOPCSL1_180t365d_prevalence_16_cnt', 'operOPCSL1_180t365d_prevalence_17_cnt', 'operOPCSL1_180t365d_prevalence_18_cnt', 'operOPCSL1_180t365d_prevalence_19_cnt', 'operOPCSL1_180t365d_prevalence_20_cnt', 'operOPCSL1_180t365d_prevalence_21_cnt', 'operOPCSL1_180t365d_prevalence_22_cnt', 'operOPCSL1_180t365d_prevalence_23_cnt', 'operOPCSL1_180t365d_prevalence_24_cnt', 'operOPCSL1_180t365d_prevalence_25_cnt', 'operOPCSL1_180t365d_prevalence_26_cnt', 'operOPCSL1_180t365d_prevalence_27_cnt', 'operOPCSL1_180t365d_prevalence_28_cnt', 'operOPCSL1_180t365d_prevalence_29_cnt', 'operOPCSL1_180t365d_prevalence_30_cnt'\n", |
|
|
2087 |
" , 'operOPCSL1_365t730d_others_cnt', 'operOPCSL1_365t730d_prevalence_1_cnt', 'operOPCSL1_365t730d_prevalence_2_cnt', 'operOPCSL1_365t730d_prevalence_3_cnt', 'operOPCSL1_365t730d_prevalence_4_cnt', 'operOPCSL1_365t730d_prevalence_5_cnt', 'operOPCSL1_365t730d_prevalence_6_cnt', 'operOPCSL1_365t730d_prevalence_7_cnt', 'operOPCSL1_365t730d_prevalence_8_cnt', 'operOPCSL1_365t730d_prevalence_9_cnt', 'operOPCSL1_365t730d_prevalence_10_cnt', 'operOPCSL1_365t730d_prevalence_11_cnt', 'operOPCSL1_365t730d_prevalence_12_cnt', 'operOPCSL1_365t730d_prevalence_13_cnt', 'operOPCSL1_365t730d_prevalence_14_cnt', 'operOPCSL1_365t730d_prevalence_15_cnt', 'operOPCSL1_365t730d_prevalence_16_cnt', 'operOPCSL1_365t730d_prevalence_17_cnt', 'operOPCSL1_365t730d_prevalence_18_cnt', 'operOPCSL1_365t730d_prevalence_19_cnt', 'operOPCSL1_365t730d_prevalence_20_cnt', 'operOPCSL1_365t730d_prevalence_21_cnt', 'operOPCSL1_365t730d_prevalence_22_cnt', 'operOPCSL1_365t730d_prevalence_23_cnt', 'operOPCSL1_365t730d_prevalence_24_cnt', 'operOPCSL1_365t730d_prevalence_25_cnt', 'operOPCSL1_365t730d_prevalence_26_cnt', 'operOPCSL1_365t730d_prevalence_27_cnt', 'operOPCSL1_365t730d_prevalence_28_cnt', 'operOPCSL1_365t730d_prevalence_29_cnt', 'operOPCSL1_365t730d_prevalence_30_cnt']\n", |
|
|
2088 |
"file_name = \"report_population_operations_\" + method_name + \"_\" + target_feature + \"_\"" |
|
|
2089 |
] |
|
|
2090 |
}, |
|
|
2091 |
{ |
|
|
2092 |
"cell_type": "code", |
|
|
2093 |
"execution_count": null, |
|
|
2094 |
"metadata": { |
|
|
2095 |
"collapsed": true, |
|
|
2096 |
"deletable": true, |
|
|
2097 |
"editable": true |
|
|
2098 |
}, |
|
|
2099 |
"outputs": [], |
|
|
2100 |
"source": [ |
|
|
2101 |
"o_summaries = population_statistics(features_extra['train'], diagnoses)\n", |
|
|
2102 |
"readers_writers.save_csv(path=CONSTANTS.io_path, title=file_name + \"train\", data=o_summaries, append=False, extension=\"csv\", header=o_summaries.columns)\n", |
|
|
2103 |
"\n", |
|
|
2104 |
"o_summaries = population_statistics(features_extra['test'], diagnoses)\n", |
|
|
2105 |
"readers_writers.save_csv(path=CONSTANTS.io_path, title=file_name + \"test\", data=o_summaries, append=False, extension=\"csv\", header=o_summaries.columns)" |
|
|
2106 |
] |
|
|
2107 |
}, |
|
|
2108 |
{ |
|
|
2109 |
"cell_type": "markdown", |
|
|
2110 |
"metadata": { |
|
|
2111 |
"deletable": true, |
|
|
2112 |
"editable": true |
|
|
2113 |
}, |
|
|
2114 |
"source": [ |
|
|
2115 |
"#### 5.2.4. Most Prevalent Main Speciality\n", |
|
|
2116 |
"Most prevalent operations variables (30-day, 1-year readmission): \n", |
|
|
2117 |
"* Total, Admissions, Emergency Readmission Rate, Prior Spells, Male (%), Age (IQR), LoS (IQR), TP, FP, FN, TN" |
|
|
2118 |
] |
|
|
2119 |
}, |
|
|
2120 |
{ |
|
|
2121 |
"cell_type": "code", |
|
|
2122 |
"execution_count": null, |
|
|
2123 |
"metadata": { |
|
|
2124 |
"collapsed": true, |
|
|
2125 |
"deletable": true, |
|
|
2126 |
"editable": true |
|
|
2127 |
}, |
|
|
2128 |
"outputs": [], |
|
|
2129 |
"source": [ |
|
|
2130 |
"diagnoses = ['mainspef_0t30d_others_cnt', 'mainspef_0t30d_prevalence_1_cnt', 'mainspef_0t30d_prevalence_2_cnt', 'mainspef_0t30d_prevalence_3_cnt', 'mainspef_0t30d_prevalence_4_cnt', 'mainspef_0t30d_prevalence_5_cnt', 'mainspef_0t30d_prevalence_6_cnt', 'mainspef_0t30d_prevalence_7_cnt', 'mainspef_0t30d_prevalence_8_cnt', 'mainspef_0t30d_prevalence_9_cnt', 'mainspef_0t30d_prevalence_10_cnt'\n", |
|
|
2131 |
" , 'mainspef_30t90d_others_cnt', 'mainspef_30t90d_prevalence_1_cnt', 'mainspef_30t90d_prevalence_2_cnt', 'mainspef_30t90d_prevalence_3_cnt', 'mainspef_30t90d_prevalence_4_cnt', 'mainspef_30t90d_prevalence_5_cnt', 'mainspef_30t90d_prevalence_6_cnt', 'mainspef_30t90d_prevalence_7_cnt', 'mainspef_30t90d_prevalence_8_cnt', 'mainspef_30t90d_prevalence_9_cnt', 'mainspef_30t90d_prevalence_10_cnt'\n", |
|
|
2132 |
" , 'mainspef_90t180d_others_cnt', 'mainspef_90t180d_prevalence_1_cnt', 'mainspef_90t180d_prevalence_2_cnt', 'mainspef_90t180d_prevalence_3_cnt', 'mainspef_90t180d_prevalence_4_cnt', 'mainspef_90t180d_prevalence_5_cnt', 'mainspef_90t180d_prevalence_6_cnt', 'mainspef_90t180d_prevalence_7_cnt', 'mainspef_90t180d_prevalence_8_cnt', 'mainspef_90t180d_prevalence_9_cnt', 'mainspef_90t180d_prevalence_10_cnt'\n", |
|
|
2133 |
" , 'mainspef_180t365d_others_cnt', 'mainspef_180t365d_prevalence_1_cnt', 'mainspef_180t365d_prevalence_2_cnt', 'mainspef_180t365d_prevalence_3_cnt', 'mainspef_180t365d_prevalence_4_cnt', 'mainspef_180t365d_prevalence_5_cnt', 'mainspef_180t365d_prevalence_6_cnt', 'mainspef_180t365d_prevalence_7_cnt', 'mainspef_180t365d_prevalence_8_cnt', 'mainspef_180t365d_prevalence_9_cnt', 'mainspef_180t365d_prevalence_10_cnt'\n", |
|
|
2134 |
" , 'mainspef_365t730d_others_cnt', 'mainspef_365t730d_prevalence_1_cnt', 'mainspef_365t730d_prevalence_2_cnt', 'mainspef_365t730d_prevalence_3_cnt', 'mainspef_365t730d_prevalence_4_cnt', 'mainspef_365t730d_prevalence_5_cnt', 'mainspef_365t730d_prevalence_6_cnt', 'mainspef_365t730d_prevalence_7_cnt', 'mainspef_365t730d_prevalence_8_cnt', 'mainspef_365t730d_prevalence_9_cnt', 'mainspef_365t730d_prevalence_10_cnt']\n", |
|
|
2135 |
"file_name = \"report_population_operations_\" + method_name + \"_\" + target_feature + \"_\"" |
|
|
2136 |
] |
|
|
2137 |
}, |
|
|
2138 |
{ |
|
|
2139 |
"cell_type": "code", |
|
|
2140 |
"execution_count": null, |
|
|
2141 |
"metadata": { |
|
|
2142 |
"collapsed": false, |
|
|
2143 |
"deletable": true, |
|
|
2144 |
"editable": true |
|
|
2145 |
}, |
|
|
2146 |
"outputs": [], |
|
|
2147 |
"source": [ |
|
|
2148 |
"o_summaries = population_statistics(features_extra['train'], diagnoses)\n", |
|
|
2149 |
"readers_writers.save_csv(path=CONSTANTS.io_path, title=file_name + \"train\", data=o_summaries, append=False, extension=\"csv\", header=o_summaries.columns)\n", |
|
|
2150 |
"\n", |
|
|
2151 |
"o_summaries = population_statistics(features_extra['test'], diagnoses)\n", |
|
|
2152 |
"readers_writers.save_csv(path=CONSTANTS.io_path, title=file_name + \"test\", data=o_summaries, append=False, extension=\"csv\", header=o_summaries.columns)" |
|
|
2153 |
] |
|
|
2154 |
}, |
|
|
2155 |
{ |
|
|
2156 |
"cell_type": "markdown", |
|
|
2157 |
"metadata": { |
|
|
2158 |
"deletable": true, |
|
|
2159 |
"editable": true |
|
|
2160 |
}, |
|
|
2161 |
"source": [ |
|
|
2162 |
"#### 5.2.5. Other Variables\n", |
|
|
2163 |
"Other variables (30-day, 1-year readmission): \n", |
|
|
2164 |
"* Total, Admissions, Emergency Readmission Rate, Prior Spells, Male (%), Age (IQR), LoS (IQR), TP, FP, FN, TN" |
|
|
2165 |
] |
|
|
2166 |
}, |
|
|
2167 |
{ |
|
|
2168 |
"cell_type": "code", |
|
|
2169 |
"execution_count": null, |
|
|
2170 |
"metadata": { |
|
|
2171 |
"collapsed": true, |
|
|
2172 |
"deletable": true, |
|
|
2173 |
"editable": true |
|
|
2174 |
}, |
|
|
2175 |
"outputs": [], |
|
|
2176 |
"source": [ |
|
|
2177 |
"diagnoses = ['gapDays_0t30d_avg', 'gapDays_30t90d_avg', 'gapDays_90t180d_avg', 'gapDays_180t365d_avg', 'gapDays_365t730d_avg', \n", |
|
|
2178 |
" 'epidur_0t30d_avg', 'epidur_30t90d_avg', 'epidur_90t180d_avg', 'epidur_180t365d_avg', 'epidur_365t730d_avg', \n", |
|
|
2179 |
" 'preopdur_0t30d_avg', 'preopdur_30t90d_avg', 'preopdur_90t180d_avg', 'preopdur_180t365d_avg', 'preopdur_365t730d_avg', \n", |
|
|
2180 |
" 'posopdur_0t30d_avg', 'posopdur_30t90d_avg', 'posopdur_90t180d_avg', 'posopdur_180t365d_avg', 'posopdur_365t730d_avg']\n", |
|
|
2181 |
"file_name = \"report_population_other_variables_\" + method_name + \"_\" + target_feature + \"_\"" |
|
|
2182 |
] |
|
|
2183 |
}, |
|
|
2184 |
{ |
|
|
2185 |
"cell_type": "code", |
|
|
2186 |
"execution_count": null, |
|
|
2187 |
"metadata": { |
|
|
2188 |
"collapsed": true, |
|
|
2189 |
"deletable": true, |
|
|
2190 |
"editable": true |
|
|
2191 |
}, |
|
|
2192 |
"outputs": [], |
|
|
2193 |
"source": [ |
|
|
2194 |
"o_summaries = population_statistics(features_extra['train'], diagnoses)\n", |
|
|
2195 |
"readers_writers.save_csv(path=CONSTANTS.io_path, title=file_name + \"train\", data=o_summaries, append=False, extension=\"csv\", header=o_summaries.columns)\n", |
|
|
2196 |
"\n", |
|
|
2197 |
"o_summaries = population_statistics(features_extra['test'], diagnoses)\n", |
|
|
2198 |
"readers_writers.save_csv(path=CONSTANTS.io_path, title=file_name + \"test\", data=o_summaries, append=False, extension=\"csv\", header=o_summaries.columns)" |
|
|
2199 |
] |
|
|
2200 |
}, |
|
|
2201 |
{ |
|
|
2202 |
"cell_type": "markdown", |
|
|
2203 |
"metadata": { |
|
|
2204 |
"deletable": true, |
|
|
2205 |
"editable": true |
|
|
2206 |
}, |
|
|
2207 |
"source": [ |
|
|
2208 |
"<br/><br/>" |
|
|
2209 |
] |
|
|
2210 |
}, |
|
|
2211 |
{ |
|
|
2212 |
"cell_type": "markdown", |
|
|
2213 |
"metadata": { |
|
|
2214 |
"deletable": true, |
|
|
2215 |
"editable": true |
|
|
2216 |
}, |
|
|
2217 |
"source": [ |
|
|
2218 |
"### 5.3. Plots" |
|
|
2219 |
] |
|
|
2220 |
}, |
|
|
2221 |
{ |
|
|
2222 |
"cell_type": "code", |
|
|
2223 |
"execution_count": null, |
|
|
2224 |
"metadata": { |
|
|
2225 |
"collapsed": true, |
|
|
2226 |
"deletable": true, |
|
|
2227 |
"editable": true |
|
|
2228 |
}, |
|
|
2229 |
"outputs": [], |
|
|
2230 |
"source": [ |
|
|
2231 |
"file_name = \"report_population_\" + method_name + \"_\" + target_feature + \"_\"" |
|
|
2232 |
] |
|
|
2233 |
}, |
|
|
2234 |
{ |
|
|
2235 |
"cell_type": "markdown", |
|
|
2236 |
"metadata": { |
|
|
2237 |
"deletable": true, |
|
|
2238 |
"editable": true |
|
|
2239 |
}, |
|
|
2240 |
"source": [ |
|
|
2241 |
"#### 5.3.1. ROC" |
|
|
2242 |
] |
|
|
2243 |
}, |
|
|
2244 |
{ |
|
|
2245 |
"cell_type": "code", |
|
|
2246 |
"execution_count": null, |
|
|
2247 |
"metadata": { |
|
|
2248 |
"collapsed": false, |
|
|
2249 |
"deletable": true, |
|
|
2250 |
"editable": true |
|
|
2251 |
}, |
|
|
2252 |
"outputs": [], |
|
|
2253 |
"source": [ |
|
|
2254 |
"fig, summaries = plots.roc(training_method.model_predict[\"test\"], features_extra[\"test\"][target_feature], \n", |
|
|
2255 |
" title=\"ROC Curve\", lw=2)\n", |
|
|
2256 |
"display(fig)" |
|
|
2257 |
] |
|
|
2258 |
}, |
|
|
2259 |
{ |
|
|
2260 |
"cell_type": "code", |
|
|
2261 |
"execution_count": null, |
|
|
2262 |
"metadata": { |
|
|
2263 |
"collapsed": false, |
|
|
2264 |
"deletable": true, |
|
|
2265 |
"editable": true |
|
|
2266 |
}, |
|
|
2267 |
"outputs": [], |
|
|
2268 |
"source": [ |
|
|
2269 |
"# save\n", |
|
|
2270 |
"plt.savefig(os.path.join(CONSTANTS.io_path, file_name + \"_roc\" + \".pdf\"), \n", |
|
|
2271 |
" dpi=300, facecolor='w', edgecolor='w', orientation='portrait', papertype=None, format=\"pdf\",\n", |
|
|
2272 |
" transparent=False, bbox_inches=None, pad_inches=0.1, frameon=None)" |
|
|
2273 |
] |
|
|
2274 |
}, |
|
|
2275 |
{ |
|
|
2276 |
"cell_type": "markdown", |
|
|
2277 |
"metadata": { |
|
|
2278 |
"deletable": true, |
|
|
2279 |
"editable": true |
|
|
2280 |
}, |
|
|
2281 |
"source": [ |
|
|
2282 |
"#### 5.3.2. Precision Recall" |
|
|
2283 |
] |
|
|
2284 |
}, |
|
|
2285 |
{ |
|
|
2286 |
"cell_type": "code", |
|
|
2287 |
"execution_count": null, |
|
|
2288 |
"metadata": { |
|
|
2289 |
"collapsed": false, |
|
|
2290 |
"deletable": true, |
|
|
2291 |
"editable": true, |
|
|
2292 |
"scrolled": true |
|
|
2293 |
}, |
|
|
2294 |
"outputs": [], |
|
|
2295 |
"source": [ |
|
|
2296 |
"fig, summaries = plots.precision_recall(training_method.model_predict[\"test\"], \n", |
|
|
2297 |
" features_extra[\"test\"][target_feature], \n", |
|
|
2298 |
" title=\"Precision-Recall Curve\", lw=2)\n", |
|
|
2299 |
"display(fig)" |
|
|
2300 |
] |
|
|
2301 |
}, |
|
|
2302 |
{ |
|
|
2303 |
"cell_type": "code", |
|
|
2304 |
"execution_count": null, |
|
|
2305 |
"metadata": { |
|
|
2306 |
"collapsed": true, |
|
|
2307 |
"deletable": true, |
|
|
2308 |
"editable": true |
|
|
2309 |
}, |
|
|
2310 |
"outputs": [], |
|
|
2311 |
"source": [ |
|
|
2312 |
"# save\n", |
|
|
2313 |
"plt.savefig(os.path.join(CONSTANTS.io_path, file_name + \"_precision_recall\" + \".pdf\"), \n", |
|
|
2314 |
" dpi=300, facecolor='w', edgecolor='w', orientation='portrait', papertype=None, format=\"pdf\",\n", |
|
|
2315 |
" transparent=False, bbox_inches=None, pad_inches=0.1, frameon=None)" |
|
|
2316 |
] |
|
|
2317 |
}, |
|
|
2318 |
{ |
|
|
2319 |
"cell_type": "markdown", |
|
|
2320 |
"metadata": { |
|
|
2321 |
"deletable": true, |
|
|
2322 |
"editable": true |
|
|
2323 |
}, |
|
|
2324 |
"source": [ |
|
|
2325 |
"#### 5.3.3. Learning Curve" |
|
|
2326 |
] |
|
|
2327 |
}, |
|
|
2328 |
{ |
|
|
2329 |
"cell_type": "code", |
|
|
2330 |
"execution_count": null, |
|
|
2331 |
"metadata": { |
|
|
2332 |
"collapsed": false, |
|
|
2333 |
"deletable": true, |
|
|
2334 |
"editable": true |
|
|
2335 |
}, |
|
|
2336 |
"outputs": [], |
|
|
2337 |
"source": [ |
|
|
2338 |
"fig, summaries = plots.learning_curve(training_method.model_train, \n", |
|
|
2339 |
" features_extra[\"test\"][features_names_selected], \n", |
|
|
2340 |
" features_extra[\"test\"][target_feature],\n", |
|
|
2341 |
" title=\"Learning Curve\", ylim=None, cv=None, n_jobs=-1, train_sizes=np.linspace(.1, 1.0, 5))\n", |
|
|
2342 |
"display(fig)" |
|
|
2343 |
] |
|
|
2344 |
}, |
|
|
2345 |
{ |
|
|
2346 |
"cell_type": "code", |
|
|
2347 |
"execution_count": null, |
|
|
2348 |
"metadata": { |
|
|
2349 |
"collapsed": true, |
|
|
2350 |
"deletable": true, |
|
|
2351 |
"editable": true |
|
|
2352 |
}, |
|
|
2353 |
"outputs": [], |
|
|
2354 |
"source": [ |
|
|
2355 |
"# save\n", |
|
|
2356 |
"plt.savefig(os.path.join(CONSTANTS.io_path, file_name + \"_learning_curve\" + \".pdf\"), \n", |
|
|
2357 |
" dpi=300, facecolor='w', edgecolor='w', orientation='portrait', papertype=None, format=\"pdf\",\n", |
|
|
2358 |
" transparent=False, bbox_inches=None, pad_inches=0.1, frameon=None)" |
|
|
2359 |
] |
|
|
2360 |
}, |
|
|
2361 |
{ |
|
|
2362 |
"cell_type": "markdown", |
|
|
2363 |
"metadata": { |
|
|
2364 |
"deletable": true, |
|
|
2365 |
"editable": true |
|
|
2366 |
}, |
|
|
2367 |
"source": [ |
|
|
2368 |
"#### 5.3.4. Validation Curve" |
|
|
2369 |
] |
|
|
2370 |
}, |
|
|
2371 |
{ |
|
|
2372 |
"cell_type": "markdown", |
|
|
2373 |
"metadata": { |
|
|
2374 |
"deletable": true, |
|
|
2375 |
"editable": true |
|
|
2376 |
}, |
|
|
2377 |
"source": [ |
|
|
2378 |
"Set the model's metadata" |
|
|
2379 |
] |
|
|
2380 |
}, |
|
|
2381 |
{ |
|
|
2382 |
"cell_type": "code", |
|
|
2383 |
"execution_count": null, |
|
|
2384 |
"metadata": { |
|
|
2385 |
"collapsed": false, |
|
|
2386 |
"deletable": true, |
|
|
2387 |
"editable": true |
|
|
2388 |
}, |
|
|
2389 |
"outputs": [], |
|
|
2390 |
"source": [ |
|
|
2391 |
"# method metadata\n", |
|
|
2392 |
"if method_name == \"lr\":\n", |
|
|
2393 |
" param_name = \"clf__C\"\n", |
|
|
2394 |
" param_range = [0.001, 0.01, 0.1, 1.0, 10.0, 100.0]\n", |
|
|
2395 |
"elif method_name == \"rfc\":\n", |
|
|
2396 |
" param_name = \"max_features\"\n", |
|
|
2397 |
" param_range = range(1, 4, 1) # range(1, 20, 1)\n", |
|
|
2398 |
"elif method_name == \"nn\":\n", |
|
|
2399 |
" param_name = \"alpha\"\n", |
|
|
2400 |
" param_range = range(1e4, 1e6, 9e4)" |
|
|
2401 |
] |
|
|
2402 |
}, |
|
|
2403 |
{ |
|
|
2404 |
"cell_type": "code", |
|
|
2405 |
"execution_count": null, |
|
|
2406 |
"metadata": { |
|
|
2407 |
"collapsed": false, |
|
|
2408 |
"deletable": true, |
|
|
2409 |
"editable": true |
|
|
2410 |
}, |
|
|
2411 |
"outputs": [], |
|
|
2412 |
"source": [ |
|
|
2413 |
"fig, summaries = plots.validation_curve(training_method.model_train, \n", |
|
|
2414 |
" features_extra[\"test\"][features_names_selected], \n", |
|
|
2415 |
" features_extra[\"test\"][target_feature],\n", |
|
|
2416 |
" param_name, param_range, \n", |
|
|
2417 |
" title=\"Learning Curve\", ylim=None, cv=None, lw=2, n_jobs=-1)\n", |
|
|
2418 |
"display(fig)" |
|
|
2419 |
] |
|
|
2420 |
}, |
|
|
2421 |
{ |
|
|
2422 |
"cell_type": "code", |
|
|
2423 |
"execution_count": null, |
|
|
2424 |
"metadata": { |
|
|
2425 |
"collapsed": true, |
|
|
2426 |
"deletable": true, |
|
|
2427 |
"editable": true |
|
|
2428 |
}, |
|
|
2429 |
"outputs": [], |
|
|
2430 |
"source": [ |
|
|
2431 |
"# save\n", |
|
|
2432 |
"plt.savefig(os.path.join(CONSTANTS.io_path, file_name + \"_validation_curve\" + \".pdf\"), \n", |
|
|
2433 |
" dpi=300, facecolor='w', edgecolor='w', orientation='portrait', papertype=None, format=\"pdf\",\n", |
|
|
2434 |
" transparent=False, bbox_inches=None, pad_inches=0.1, frameon=None)" |
|
|
2435 |
] |
|
|
2436 |
}, |
|
|
2437 |
{ |
|
|
2438 |
"cell_type": "markdown", |
|
|
2439 |
"metadata": { |
|
|
2440 |
"deletable": true, |
|
|
2441 |
"editable": true |
|
|
2442 |
}, |
|
|
2443 |
"source": [ |
|
|
2444 |
"<br/><br/>" |
|
|
2445 |
] |
|
|
2446 |
}, |
|
|
2447 |
{ |
|
|
2448 |
"cell_type": "markdown", |
|
|
2449 |
"metadata": { |
|
|
2450 |
"collapsed": true, |
|
|
2451 |
"deletable": true, |
|
|
2452 |
"editable": true |
|
|
2453 |
}, |
|
|
2454 |
"source": [ |
|
|
2455 |
"Fin!" |
|
|
2456 |
] |
|
|
2457 |
} |
|
|
2458 |
], |
|
|
2459 |
"metadata": { |
|
|
2460 |
"kernelspec": { |
|
|
2461 |
"display_name": "Python 3", |
|
|
2462 |
"language": "python", |
|
|
2463 |
"name": "python3" |
|
|
2464 |
}, |
|
|
2465 |
"language_info": { |
|
|
2466 |
"codemirror_mode": { |
|
|
2467 |
"name": "ipython", |
|
|
2468 |
"version": 3 |
|
|
2469 |
}, |
|
|
2470 |
"file_extension": ".py", |
|
|
2471 |
"mimetype": "text/x-python", |
|
|
2472 |
"name": "python", |
|
|
2473 |
"nbconvert_exporter": "python", |
|
|
2474 |
"pygments_lexer": "ipython3", |
|
|
2475 |
"version": "3.5.3" |
|
|
2476 |
} |
|
|
2477 |
}, |
|
|
2478 |
"nbformat": 4, |
|
|
2479 |
"nbformat_minor": 2 |
|
|
2480 |
} |