|
a |
|
b/TCARER_plots.ipynb |
|
|
1 |
{ |
|
|
2 |
"cells": [ |
|
|
3 |
{ |
|
|
4 |
"cell_type": "markdown", |
|
|
5 |
"metadata": { |
|
|
6 |
"deletable": true, |
|
|
7 |
"editable": true |
|
|
8 |
}, |
|
|
9 |
"source": [ |
|
|
10 |
"## Initialise" |
|
|
11 |
] |
|
|
12 |
}, |
|
|
13 |
{ |
|
|
14 |
"cell_type": "code", |
|
|
15 |
"execution_count": 20, |
|
|
16 |
"metadata": { |
|
|
17 |
"collapsed": false, |
|
|
18 |
"deletable": true, |
|
|
19 |
"editable": true |
|
|
20 |
}, |
|
|
21 |
"outputs": [ |
|
|
22 |
{ |
|
|
23 |
"name": "stdout", |
|
|
24 |
"output_type": "stream", |
|
|
25 |
"text": [ |
|
|
26 |
"The autoreload extension is already loaded. To reload it, use:\n", |
|
|
27 |
" %reload_ext autoreload\n" |
|
|
28 |
] |
|
|
29 |
} |
|
|
30 |
], |
|
|
31 |
"source": [ |
|
|
32 |
"# Reload modules \n", |
|
|
33 |
"# It is an optional step. It is useful to run when external Python modules are being modified\n", |
|
|
34 |
"# It is reloading all modules (except those excluded by %aimport) every time before executing the Python code typed.\n", |
|
|
35 |
"# Note: It may conflict with serialisation, when external modules are being modified\n", |
|
|
36 |
"\n", |
|
|
37 |
"%load_ext autoreload \n", |
|
|
38 |
"%autoreload 2" |
|
|
39 |
] |
|
|
40 |
}, |
|
|
41 |
{ |
|
|
42 |
"cell_type": "code", |
|
|
43 |
"execution_count": 21, |
|
|
44 |
"metadata": { |
|
|
45 |
"collapsed": true, |
|
|
46 |
"deletable": true, |
|
|
47 |
"editable": true |
|
|
48 |
}, |
|
|
49 |
"outputs": [], |
|
|
50 |
"source": [ |
|
|
51 |
"# Import Python 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 |
"from IPython.display import display, HTML\n", |
|
|
58 |
"import numpy as np\n", |
|
|
59 |
"import matplotlib.pyplot as plt" |
|
|
60 |
] |
|
|
61 |
}, |
|
|
62 |
{ |
|
|
63 |
"cell_type": "code", |
|
|
64 |
"execution_count": 22, |
|
|
65 |
"metadata": { |
|
|
66 |
"collapsed": false, |
|
|
67 |
"deletable": true, |
|
|
68 |
"editable": true |
|
|
69 |
}, |
|
|
70 |
"outputs": [], |
|
|
71 |
"source": [ |
|
|
72 |
"# Import local Python modules\n", |
|
|
73 |
"from Configs.CONSTANTS import CONSTANTS\n", |
|
|
74 |
"from Configs.Logger import Logger\n", |
|
|
75 |
"from ReadersWriters.ReadersWriters import ReadersWriters\n", |
|
|
76 |
"from Stats.Plots import Plots" |
|
|
77 |
] |
|
|
78 |
}, |
|
|
79 |
{ |
|
|
80 |
"cell_type": "code", |
|
|
81 |
"execution_count": 23, |
|
|
82 |
"metadata": { |
|
|
83 |
"collapsed": false, |
|
|
84 |
"deletable": true, |
|
|
85 |
"editable": true |
|
|
86 |
}, |
|
|
87 |
"outputs": [ |
|
|
88 |
{ |
|
|
89 |
"name": "stdout", |
|
|
90 |
"output_type": "stream", |
|
|
91 |
"text": [ |
|
|
92 |
"\n", |
|
|
93 |
"Make sure the correct Python interpreter is used!\n", |
|
|
94 |
"3.5.3 (v3.5.3:1880cb95a742, Jan 16 2017, 16:02:32) [MSC v.1900 64 bit (AMD64)]\n", |
|
|
95 |
"\n", |
|
|
96 |
"Make sure sys.path of the Python interpreter is correct!\n", |
|
|
97 |
"C:\\Users\\eagle\\Documents\\GitHub\\Analytics_UoW\\TCARER\n" |
|
|
98 |
] |
|
|
99 |
} |
|
|
100 |
], |
|
|
101 |
"source": [ |
|
|
102 |
"# Check the interpreter\n", |
|
|
103 |
"print(\"\\nMake sure the correct Python interpreter is used!\")\n", |
|
|
104 |
"print(sys.version)\n", |
|
|
105 |
"print(\"\\nMake sure sys.path of the Python interpreter is correct!\")\n", |
|
|
106 |
"print(os.getcwd())" |
|
|
107 |
] |
|
|
108 |
}, |
|
|
109 |
{ |
|
|
110 |
"cell_type": "markdown", |
|
|
111 |
"metadata": { |
|
|
112 |
"deletable": true, |
|
|
113 |
"editable": true |
|
|
114 |
}, |
|
|
115 |
"source": [ |
|
|
116 |
"Set constants" |
|
|
117 |
] |
|
|
118 |
}, |
|
|
119 |
{ |
|
|
120 |
"cell_type": "code", |
|
|
121 |
"execution_count": 24, |
|
|
122 |
"metadata": { |
|
|
123 |
"collapsed": false, |
|
|
124 |
"deletable": true, |
|
|
125 |
"editable": true |
|
|
126 |
}, |
|
|
127 |
"outputs": [ |
|
|
128 |
{ |
|
|
129 |
"name": "stdout", |
|
|
130 |
"output_type": "stream", |
|
|
131 |
"text": [ |
|
|
132 |
"\n", |
|
|
133 |
" The full path of the configuration file: \n", |
|
|
134 |
"\t C:\\Users\\eagle\\Documents\\GitHub\\Analytics_UoW\\TCARER\\ConfigInputs\\CONFIGURATIONS.ini \n", |
|
|
135 |
" The full path of the output folder: \n", |
|
|
136 |
"\t C:\\Users\\eagle\\Documents\\GitHub\\tmp\\TCARER\\scores_adhoc \n", |
|
|
137 |
" The application name (the suffix of the outputs file name): \n", |
|
|
138 |
"\t tcarerPlots\n" |
|
|
139 |
] |
|
|
140 |
} |
|
|
141 |
], |
|
|
142 |
"source": [ |
|
|
143 |
"config_path = os.path.abspath(\"ConfigInputs/CONFIGURATIONS.ini\")\n", |
|
|
144 |
"io_path = os.path.abspath(\"../../tmp/TCARER/scores_adhoc\")\n", |
|
|
145 |
"app_name = 'tcarerPlots'\n", |
|
|
146 |
"\n", |
|
|
147 |
"print(\"\\n The full path of the configuration file: \\n\\t\", config_path,\n", |
|
|
148 |
" \"\\n The full path of the output folder: \\n\\t\", io_path,\n", |
|
|
149 |
" \"\\n The application name (the suffix of the outputs file name): \\n\\t\", app_name)" |
|
|
150 |
] |
|
|
151 |
}, |
|
|
152 |
{ |
|
|
153 |
"cell_type": "markdown", |
|
|
154 |
"metadata": { |
|
|
155 |
"deletable": true, |
|
|
156 |
"editable": true |
|
|
157 |
}, |
|
|
158 |
"source": [ |
|
|
159 |
"<br/>" |
|
|
160 |
] |
|
|
161 |
}, |
|
|
162 |
{ |
|
|
163 |
"cell_type": "code", |
|
|
164 |
"execution_count": 25, |
|
|
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 12:29:33,032 - tcarerPlots - INFO - Creating 'C:\\Users\\eagle\\Documents\\GitHub\\tmp\\TCARER\\scores_adhoc\\tcarerPlots.log' File.\n", |
|
|
176 |
"2017-10-29 12:29:33,032 - tcarerPlots - INFO - Creating 'C:\\Users\\eagle\\Documents\\GitHub\\tmp\\TCARER\\scores_adhoc\\tcarerPlots.log' File.\n", |
|
|
177 |
"2017-10-29 12:29:33,032 - tcarerPlots - INFO - Creating 'C:\\Users\\eagle\\Documents\\GitHub\\tmp\\TCARER\\scores_adhoc\\tcarerPlots.log' File.\n" |
|
|
178 |
] |
|
|
179 |
} |
|
|
180 |
], |
|
|
181 |
"source": [ |
|
|
182 |
"if not os.path.exists(io_path):\n", |
|
|
183 |
" os.makedirs(io_path, exist_ok=True)\n", |
|
|
184 |
"\n", |
|
|
185 |
"logger = Logger(path=io_path, app_name=app_name, ext=\"log\")\n", |
|
|
186 |
"logger = logging.getLogger(app_name)" |
|
|
187 |
] |
|
|
188 |
}, |
|
|
189 |
{ |
|
|
190 |
"cell_type": "code", |
|
|
191 |
"execution_count": 26, |
|
|
192 |
"metadata": { |
|
|
193 |
"collapsed": true, |
|
|
194 |
"deletable": true, |
|
|
195 |
"editable": true |
|
|
196 |
}, |
|
|
197 |
"outputs": [], |
|
|
198 |
"source": [ |
|
|
199 |
"# Initialise constants \n", |
|
|
200 |
"CONSTANTS.set(io_path, app_name)" |
|
|
201 |
] |
|
|
202 |
}, |
|
|
203 |
{ |
|
|
204 |
"cell_type": "code", |
|
|
205 |
"execution_count": 27, |
|
|
206 |
"metadata": { |
|
|
207 |
"collapsed": true, |
|
|
208 |
"deletable": true, |
|
|
209 |
"editable": true |
|
|
210 |
}, |
|
|
211 |
"outputs": [], |
|
|
212 |
"source": [ |
|
|
213 |
"# Initialise other classes\n", |
|
|
214 |
"readers_writers = ReadersWriters()\n", |
|
|
215 |
"plots = Plots()" |
|
|
216 |
] |
|
|
217 |
}, |
|
|
218 |
{ |
|
|
219 |
"cell_type": "code", |
|
|
220 |
"execution_count": 35, |
|
|
221 |
"metadata": { |
|
|
222 |
"collapsed": true, |
|
|
223 |
"deletable": true, |
|
|
224 |
"editable": true |
|
|
225 |
}, |
|
|
226 |
"outputs": [], |
|
|
227 |
"source": [ |
|
|
228 |
"samples = [\"Basic_prototype\"]\n", |
|
|
229 |
"targets = [\"365\"]\n", |
|
|
230 |
"submodels = [\"rfc\", \"wdnn\"]\n", |
|
|
231 |
"paths = [os.path.abspath(\"../../tmp/TCARER/Basic_prototype\")]\n", |
|
|
232 |
"file_names = [[\"Step_09_Model_rfc_label365\", \"Step_09_Model_wdnn_label365\"]]" |
|
|
233 |
] |
|
|
234 |
}, |
|
|
235 |
{ |
|
|
236 |
"cell_type": "markdown", |
|
|
237 |
"metadata": { |
|
|
238 |
"deletable": true, |
|
|
239 |
"editable": true |
|
|
240 |
}, |
|
|
241 |
"source": [ |
|
|
242 |
"<br/><br/>" |
|
|
243 |
] |
|
|
244 |
}, |
|
|
245 |
{ |
|
|
246 |
"cell_type": "markdown", |
|
|
247 |
"metadata": { |
|
|
248 |
"deletable": true, |
|
|
249 |
"editable": true |
|
|
250 |
}, |
|
|
251 |
"source": [ |
|
|
252 |
"## Load Predictions" |
|
|
253 |
] |
|
|
254 |
}, |
|
|
255 |
{ |
|
|
256 |
"cell_type": "code", |
|
|
257 |
"execution_count": 37, |
|
|
258 |
"metadata": { |
|
|
259 |
"collapsed": false, |
|
|
260 |
"deletable": true, |
|
|
261 |
"editable": true, |
|
|
262 |
"scrolled": true |
|
|
263 |
}, |
|
|
264 |
"outputs": [], |
|
|
265 |
"source": [ |
|
|
266 |
"models = dict()\n", |
|
|
267 |
"for i in range(len(samples)):\n", |
|
|
268 |
" models[samples[i]] = dict()\n", |
|
|
269 |
" for j in range(len(targets)):\n", |
|
|
270 |
" models[samples[i]][targets[j]] = dict()\n", |
|
|
271 |
" for k in range(len(submodels)):\n", |
|
|
272 |
" models[samples[i]][targets[j]][submodels[k]] = \\\n", |
|
|
273 |
" readers_writers.load_serialised(path=paths[i], title=file_names[j][k])" |
|
|
274 |
] |
|
|
275 |
}, |
|
|
276 |
{ |
|
|
277 |
"cell_type": "markdown", |
|
|
278 |
"metadata": { |
|
|
279 |
"deletable": true, |
|
|
280 |
"editable": true |
|
|
281 |
}, |
|
|
282 |
"source": [ |
|
|
283 |
"hack - correction of dictionaries" |
|
|
284 |
] |
|
|
285 |
}, |
|
|
286 |
{ |
|
|
287 |
"cell_type": "code", |
|
|
288 |
"execution_count": 40, |
|
|
289 |
"metadata": { |
|
|
290 |
"collapsed": false, |
|
|
291 |
"deletable": true, |
|
|
292 |
"editable": true |
|
|
293 |
}, |
|
|
294 |
"outputs": [ |
|
|
295 |
{ |
|
|
296 |
"ename": "KeyError", |
|
|
297 |
"evalue": "'wdnn'", |
|
|
298 |
"output_type": "error", |
|
|
299 |
"traceback": [ |
|
|
300 |
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", |
|
|
301 |
"\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", |
|
|
302 |
"\u001b[0;32m<ipython-input-40-a1f912f3713b>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msamples\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[1;32m 2\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mj\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtargets\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----> 3\u001b[0;31m \u001b[0mmodels\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0msamples\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mtargets\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mj\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"wdnn\"\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m{\u001b[0m\u001b[1;34m'model_predict'\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mmodels\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0msamples\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mtargets\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mj\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"wdnn\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", |
|
|
303 |
"\u001b[0;31mKeyError\u001b[0m: 'wdnn'" |
|
|
304 |
] |
|
|
305 |
} |
|
|
306 |
], |
|
|
307 |
"source": [ |
|
|
308 |
"for i in range(len(samples)):\n", |
|
|
309 |
" for j in range(len(targets)):\n", |
|
|
310 |
" models[samples[i]][targets[j]][\"wdnn\"] = {'model_predict': models[samples[i]][targets[j]][\"wdnn\"]}" |
|
|
311 |
] |
|
|
312 |
}, |
|
|
313 |
{ |
|
|
314 |
"cell_type": "code", |
|
|
315 |
"execution_count": 39, |
|
|
316 |
"metadata": { |
|
|
317 |
"collapsed": false, |
|
|
318 |
"deletable": true, |
|
|
319 |
"editable": true |
|
|
320 |
}, |
|
|
321 |
"outputs": [ |
|
|
322 |
{ |
|
|
323 |
"ename": "KeyError", |
|
|
324 |
"evalue": "'sample-1'", |
|
|
325 |
"output_type": "error", |
|
|
326 |
"traceback": [ |
|
|
327 |
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", |
|
|
328 |
"\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", |
|
|
329 |
"\u001b[0;32m<ipython-input-39-0533bcf87ed4>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mmodels\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"sample-1\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"30\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"wdnn\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'model_predict'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'test'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'score'\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0marray\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mmodels\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"sample-1\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"30\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"wdnn\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'model_predict'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'test'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'predict_proba'\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[0m\u001b[1;32m 2\u001b[0m \u001b[0mmodels\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"sample-1\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"365\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"wdnn\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'model_predict'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'test'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'score'\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0marray\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mmodels\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"sample-1\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"365\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"wdnn\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'model_predict'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'test'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'predict_proba'\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[1;32m 3\u001b[0m \u001b[0mmodels\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"sample-2\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"30\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"wdnn\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'model_predict'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'test'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'score'\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0marray\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mmodels\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"sample-2\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"30\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"wdnn\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'model_predict'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'test'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'predict_proba'\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[1;32m 4\u001b[0m \u001b[0mmodels\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"sample-2\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"365\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"wdnn\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'model_predict'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'test'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'score'\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0marray\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mmodels\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"sample-2\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"365\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"wdnn\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'model_predict'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'test'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'predict_proba'\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", |
|
|
330 |
"\u001b[0;31mKeyError\u001b[0m: 'sample-1'" |
|
|
331 |
] |
|
|
332 |
} |
|
|
333 |
], |
|
|
334 |
"source": [ |
|
|
335 |
"models[\"sample-1\"][\"30\"][\"wdnn\"]['model_predict']['test']['score'] = np.array([i[1] for i in models[\"sample-1\"][\"30\"][\"wdnn\"]['model_predict']['test']['predict_proba']])\n", |
|
|
336 |
"models[\"sample-1\"][\"365\"][\"wdnn\"]['model_predict']['test']['score'] = np.array([i[1] for i in models[\"sample-1\"][\"365\"][\"wdnn\"]['model_predict']['test']['predict_proba']])\n", |
|
|
337 |
"models[\"sample-2\"][\"30\"][\"wdnn\"]['model_predict']['test']['score'] = np.array([i[1] for i in models[\"sample-2\"][\"30\"][\"wdnn\"]['model_predict']['test']['predict_proba']])\n", |
|
|
338 |
"models[\"sample-2\"][\"365\"][\"wdnn\"]['model_predict']['test']['score'] = np.array([i[1] for i in models[\"sample-2\"][\"365\"][\"wdnn\"]['model_predict']['test']['predict_proba']])" |
|
|
339 |
] |
|
|
340 |
}, |
|
|
341 |
{ |
|
|
342 |
"cell_type": "markdown", |
|
|
343 |
"metadata": { |
|
|
344 |
"deletable": true, |
|
|
345 |
"editable": true |
|
|
346 |
}, |
|
|
347 |
"source": [ |
|
|
348 |
"<br/><br/>\n", |
|
|
349 |
"temporary solution - Load samples" |
|
|
350 |
] |
|
|
351 |
}, |
|
|
352 |
{ |
|
|
353 |
"cell_type": "code", |
|
|
354 |
"execution_count": null, |
|
|
355 |
"metadata": { |
|
|
356 |
"collapsed": true, |
|
|
357 |
"deletable": true, |
|
|
358 |
"editable": true |
|
|
359 |
}, |
|
|
360 |
"outputs": [], |
|
|
361 |
"source": [ |
|
|
362 |
"file_names = [\"Step_07_Features\", \"Step_07_Features\"]" |
|
|
363 |
] |
|
|
364 |
}, |
|
|
365 |
{ |
|
|
366 |
"cell_type": "code", |
|
|
367 |
"execution_count": null, |
|
|
368 |
"metadata": { |
|
|
369 |
"collapsed": true, |
|
|
370 |
"deletable": true, |
|
|
371 |
"editable": true, |
|
|
372 |
"scrolled": true |
|
|
373 |
}, |
|
|
374 |
"outputs": [], |
|
|
375 |
"source": [ |
|
|
376 |
"target_labels = dict()\n", |
|
|
377 |
"for i in range(len(samples)):\n", |
|
|
378 |
" target_labels[samples[i]] = readers_writers.load_serialised(path=paths[i], title=file_names[i])[\"test_target\"]\n", |
|
|
379 |
" \n", |
|
|
380 |
"for i in range(len(samples)):\n", |
|
|
381 |
" target_labels[samples[i]] = {\"30\": target_labels[samples[i]][\"label30\"], \n", |
|
|
382 |
" \"365\": target_labels[samples[i]][\"label365\"]}\n", |
|
|
383 |
" target_labels[\"label30\"] = None\n", |
|
|
384 |
" target_labels[\"label365\"] = None\n", |
|
|
385 |
"\n", |
|
|
386 |
"gc.collect()" |
|
|
387 |
] |
|
|
388 |
}, |
|
|
389 |
{ |
|
|
390 |
"cell_type": "markdown", |
|
|
391 |
"metadata": { |
|
|
392 |
"collapsed": true, |
|
|
393 |
"deletable": true, |
|
|
394 |
"editable": true |
|
|
395 |
}, |
|
|
396 |
"source": [ |
|
|
397 |
"temporary solution - correction of wdnn labels" |
|
|
398 |
] |
|
|
399 |
}, |
|
|
400 |
{ |
|
|
401 |
"cell_type": "code", |
|
|
402 |
"execution_count": null, |
|
|
403 |
"metadata": { |
|
|
404 |
"collapsed": true, |
|
|
405 |
"deletable": true, |
|
|
406 |
"editable": true |
|
|
407 |
}, |
|
|
408 |
"outputs": [], |
|
|
409 |
"source": [ |
|
|
410 |
"for sample in samples:\n", |
|
|
411 |
" for target in targets:\n", |
|
|
412 |
" print(len(target_labels[sample][target]), len(models[sample][target][\"wdnn\"]['model_predict']['test']['score']))\n", |
|
|
413 |
" target_labels[sample][target] = np.append(target_labels[sample][target], target_labels[sample][target])\n", |
|
|
414 |
" target_labels[sample][target] = target_labels[sample][target][0:len(models[sample][target][\"wdnn\"]['model_predict']['test']['score'])]" |
|
|
415 |
] |
|
|
416 |
}, |
|
|
417 |
{ |
|
|
418 |
"cell_type": "markdown", |
|
|
419 |
"metadata": { |
|
|
420 |
"deletable": true, |
|
|
421 |
"editable": true |
|
|
422 |
}, |
|
|
423 |
"source": [ |
|
|
424 |
"<br/><br/><br/>" |
|
|
425 |
] |
|
|
426 |
}, |
|
|
427 |
{ |
|
|
428 |
"cell_type": "markdown", |
|
|
429 |
"metadata": { |
|
|
430 |
"deletable": true, |
|
|
431 |
"editable": true |
|
|
432 |
}, |
|
|
433 |
"source": [ |
|
|
434 |
"## Save" |
|
|
435 |
] |
|
|
436 |
}, |
|
|
437 |
{ |
|
|
438 |
"cell_type": "code", |
|
|
439 |
"execution_count": null, |
|
|
440 |
"metadata": { |
|
|
441 |
"collapsed": true, |
|
|
442 |
"deletable": true, |
|
|
443 |
"editable": true |
|
|
444 |
}, |
|
|
445 |
"outputs": [], |
|
|
446 |
"source": [ |
|
|
447 |
"file_name = \"saved_models\"\n", |
|
|
448 |
"readers_writers.save_serialised(path=io_path, title=file_name, objects=models)\n", |
|
|
449 |
"\n", |
|
|
450 |
"file_name = \"saved_target_labels\"\n", |
|
|
451 |
"readers_writers.save_serialised(path=io_path, title=file_name, objects=target_labels)" |
|
|
452 |
] |
|
|
453 |
}, |
|
|
454 |
{ |
|
|
455 |
"cell_type": "markdown", |
|
|
456 |
"metadata": { |
|
|
457 |
"deletable": true, |
|
|
458 |
"editable": true |
|
|
459 |
}, |
|
|
460 |
"source": [ |
|
|
461 |
"## Load" |
|
|
462 |
] |
|
|
463 |
}, |
|
|
464 |
{ |
|
|
465 |
"cell_type": "code", |
|
|
466 |
"execution_count": null, |
|
|
467 |
"metadata": { |
|
|
468 |
"collapsed": false, |
|
|
469 |
"deletable": true, |
|
|
470 |
"editable": true |
|
|
471 |
}, |
|
|
472 |
"outputs": [], |
|
|
473 |
"source": [ |
|
|
474 |
"file_name = \"saved_models\"\n", |
|
|
475 |
"models = readers_writers.load_serialised(path=io_path, title=file_name)\n", |
|
|
476 |
"\n", |
|
|
477 |
"file_name = \"saved_target_labels\"\n", |
|
|
478 |
"target_labels = readers_writers.load_serialised(path=io_path, title=file_name)" |
|
|
479 |
] |
|
|
480 |
}, |
|
|
481 |
{ |
|
|
482 |
"cell_type": "markdown", |
|
|
483 |
"metadata": { |
|
|
484 |
"deletable": true, |
|
|
485 |
"editable": true |
|
|
486 |
}, |
|
|
487 |
"source": [ |
|
|
488 |
"<br/><br/>" |
|
|
489 |
] |
|
|
490 |
}, |
|
|
491 |
{ |
|
|
492 |
"cell_type": "markdown", |
|
|
493 |
"metadata": { |
|
|
494 |
"deletable": true, |
|
|
495 |
"editable": true |
|
|
496 |
}, |
|
|
497 |
"source": [ |
|
|
498 |
"## Plot" |
|
|
499 |
] |
|
|
500 |
}, |
|
|
501 |
{ |
|
|
502 |
"cell_type": "code", |
|
|
503 |
"execution_count": null, |
|
|
504 |
"metadata": { |
|
|
505 |
"collapsed": true, |
|
|
506 |
"deletable": true, |
|
|
507 |
"editable": true |
|
|
508 |
}, |
|
|
509 |
"outputs": [], |
|
|
510 |
"source": [ |
|
|
511 |
"file_name = \"Combined_plots\"\n", |
|
|
512 |
"\n", |
|
|
513 |
"#%pylab inline\n", |
|
|
514 |
"#pylab.rcParams['figure.figsize'] = (10, 10)" |
|
|
515 |
] |
|
|
516 |
}, |
|
|
517 |
{ |
|
|
518 |
"cell_type": "markdown", |
|
|
519 |
"metadata": { |
|
|
520 |
"deletable": true, |
|
|
521 |
"editable": true |
|
|
522 |
}, |
|
|
523 |
"source": [ |
|
|
524 |
"Combine" |
|
|
525 |
] |
|
|
526 |
}, |
|
|
527 |
{ |
|
|
528 |
"cell_type": "code", |
|
|
529 |
"execution_count": null, |
|
|
530 |
"metadata": { |
|
|
531 |
"collapsed": true, |
|
|
532 |
"deletable": true, |
|
|
533 |
"editable": true |
|
|
534 |
}, |
|
|
535 |
"outputs": [], |
|
|
536 |
"source": [ |
|
|
537 |
"markers = {'.': 'point', ',': 'pixel', 'o': 'circle', 'v': 'triangle_down', '^': 'triangle_up', '<': 'triangle_left', '>': 'triangle_right', '1': 'tri_down', '2': 'tri_up', '3': 'tri_left', '4': 'tri_right', '8': 'octagon', 's': 'square', 'p': 'pentagon', '*': 'star', 'h': 'hexagon1', 'H': 'hexagon2', '+': 'plus', 'x': 'x', 'D': 'diamond', 'd': 'thin_diamond', '|': 'vline', '_': 'hline', 'P': 'plus_filled', 'X': 'x_filled', 0: 'tickleft', 1: 'tickright', 2: 'tickup', 3: 'tickdown', 4: 'caretleft', 5: 'caretright', 6: 'caretup', 7: 'caretdown', 8: 'caretleftbase', 9: 'caretrightbase', 10: 'caretupbase', 11: 'caretdownbase', 'None': 'nothing', None: 'nothing', ' ': 'nothing', '': 'nothing'}\n", |
|
|
538 |
"scores_list = []\n", |
|
|
539 |
"target_labels_list = []\n", |
|
|
540 |
"label_list = []\n", |
|
|
541 |
"marker_list = ['.', 'o', 'v', '2', 'p', 's', '*', '+', '|'] #['.', 'o', 'v', '2', 'p', 's', '*', '+', '|']\n", |
|
|
542 |
"linestyle_list = [':', ':', ':', ':', ':', ':', ':', ':', ':'] #[':', '-.', '--', '-', ':', '-.', '--', '-', ':'] \n", |
|
|
543 |
"color_list = ['grey', 'firebrick', 'coral', 'darkgreen', 'coral', 'mediumblue', 'lightseagreen', 'blueviolet', 'darkgray']\n", |
|
|
544 |
"\n", |
|
|
545 |
"for sample in samples:\n", |
|
|
546 |
" for target in targets:\n", |
|
|
547 |
" for submodel in submodels:\n", |
|
|
548 |
" scores_list.append(models[sample][target][submodel]['model_predict']['test']['score'])\n", |
|
|
549 |
" target_labels_list.append(np.array(target_labels[sample][target][\n", |
|
|
550 |
" 0:len(models[sample][target][submodel]['model_predict']['test']['score'])]))\n", |
|
|
551 |
" label_list.append(sample + \", \" + submodel + \"-\" + target)" |
|
|
552 |
] |
|
|
553 |
}, |
|
|
554 |
{ |
|
|
555 |
"cell_type": "markdown", |
|
|
556 |
"metadata": { |
|
|
557 |
"deletable": true, |
|
|
558 |
"editable": true |
|
|
559 |
}, |
|
|
560 |
"source": [ |
|
|
561 |
"### ROC Plot" |
|
|
562 |
] |
|
|
563 |
}, |
|
|
564 |
{ |
|
|
565 |
"cell_type": "code", |
|
|
566 |
"execution_count": null, |
|
|
567 |
"metadata": { |
|
|
568 |
"collapsed": false, |
|
|
569 |
"deletable": true, |
|
|
570 |
"editable": true |
|
|
571 |
}, |
|
|
572 |
"outputs": [], |
|
|
573 |
"source": [ |
|
|
574 |
"plt.clf()\n", |
|
|
575 |
"fig, o_summaries = plots.roc_multiple(scores_list, target_labels_list, \n", |
|
|
576 |
" label_list=label_list, marker_list=marker_list, \n", |
|
|
577 |
" linestyle_list=linestyle_list, color_list=color_list, \n", |
|
|
578 |
" lw=2, markersize=8, legend_prop=15, legend_markerscale=1)" |
|
|
579 |
] |
|
|
580 |
}, |
|
|
581 |
{ |
|
|
582 |
"cell_type": "code", |
|
|
583 |
"execution_count": null, |
|
|
584 |
"metadata": { |
|
|
585 |
"collapsed": false, |
|
|
586 |
"deletable": true, |
|
|
587 |
"editable": true |
|
|
588 |
}, |
|
|
589 |
"outputs": [], |
|
|
590 |
"source": [ |
|
|
591 |
"display(fig)" |
|
|
592 |
] |
|
|
593 |
}, |
|
|
594 |
{ |
|
|
595 |
"cell_type": "code", |
|
|
596 |
"execution_count": null, |
|
|
597 |
"metadata": { |
|
|
598 |
"collapsed": true, |
|
|
599 |
"deletable": true, |
|
|
600 |
"editable": true |
|
|
601 |
}, |
|
|
602 |
"outputs": [], |
|
|
603 |
"source": [ |
|
|
604 |
"# save\n", |
|
|
605 |
"fig.savefig(os.path.join(io_path, file_name + '_roc.png'), \n", |
|
|
606 |
" dpi=1500, facecolor='w', edgecolor='w', orientation='portrait', papertype=None, format='png',\n", |
|
|
607 |
" transparent=False, bbox_inches=None, pad_inches=0.1, frameon=None)\n", |
|
|
608 |
"plt.clf()" |
|
|
609 |
] |
|
|
610 |
}, |
|
|
611 |
{ |
|
|
612 |
"cell_type": "markdown", |
|
|
613 |
"metadata": { |
|
|
614 |
"deletable": true, |
|
|
615 |
"editable": true |
|
|
616 |
}, |
|
|
617 |
"source": [ |
|
|
618 |
"### Precision-Recall Plot" |
|
|
619 |
] |
|
|
620 |
}, |
|
|
621 |
{ |
|
|
622 |
"cell_type": "code", |
|
|
623 |
"execution_count": null, |
|
|
624 |
"metadata": { |
|
|
625 |
"collapsed": false, |
|
|
626 |
"deletable": true, |
|
|
627 |
"editable": true |
|
|
628 |
}, |
|
|
629 |
"outputs": [], |
|
|
630 |
"source": [ |
|
|
631 |
"plt.clf()\n", |
|
|
632 |
"fig, o_summaries = plots.precision_recall_multiple(scores_list, target_labels_list, \n", |
|
|
633 |
" label_list=label_list, marker_list=marker_list, \n", |
|
|
634 |
" linestyle_list=linestyle_list, color_list=color_list,\n", |
|
|
635 |
" lw=2, markersize=8, legend_prop=10, legend_markerscale=1)" |
|
|
636 |
] |
|
|
637 |
}, |
|
|
638 |
{ |
|
|
639 |
"cell_type": "code", |
|
|
640 |
"execution_count": null, |
|
|
641 |
"metadata": { |
|
|
642 |
"collapsed": false, |
|
|
643 |
"deletable": true, |
|
|
644 |
"editable": true |
|
|
645 |
}, |
|
|
646 |
"outputs": [], |
|
|
647 |
"source": [ |
|
|
648 |
"display(fig)" |
|
|
649 |
] |
|
|
650 |
}, |
|
|
651 |
{ |
|
|
652 |
"cell_type": "code", |
|
|
653 |
"execution_count": null, |
|
|
654 |
"metadata": { |
|
|
655 |
"collapsed": true, |
|
|
656 |
"deletable": true, |
|
|
657 |
"editable": true |
|
|
658 |
}, |
|
|
659 |
"outputs": [], |
|
|
660 |
"source": [ |
|
|
661 |
"# save\n", |
|
|
662 |
"fig.savefig(os.path.join(io_path, file_name + '_precision_recall.png'), \n", |
|
|
663 |
" dpi=1500, facecolor='w', edgecolor='w', orientation='portrait', papertype=None, format='png',\n", |
|
|
664 |
" transparent=False, bbox_inches=None, pad_inches=0.1, frameon=None)\n", |
|
|
665 |
"plt.clf()" |
|
|
666 |
] |
|
|
667 |
}, |
|
|
668 |
{ |
|
|
669 |
"cell_type": "markdown", |
|
|
670 |
"metadata": { |
|
|
671 |
"deletable": true, |
|
|
672 |
"editable": true |
|
|
673 |
}, |
|
|
674 |
"source": [ |
|
|
675 |
"Fin!" |
|
|
676 |
] |
|
|
677 |
} |
|
|
678 |
], |
|
|
679 |
"metadata": { |
|
|
680 |
"kernelspec": { |
|
|
681 |
"display_name": "Python 3", |
|
|
682 |
"language": "python", |
|
|
683 |
"name": "python3" |
|
|
684 |
}, |
|
|
685 |
"language_info": { |
|
|
686 |
"codemirror_mode": { |
|
|
687 |
"name": "ipython", |
|
|
688 |
"version": 3 |
|
|
689 |
}, |
|
|
690 |
"file_extension": ".py", |
|
|
691 |
"mimetype": "text/x-python", |
|
|
692 |
"name": "python", |
|
|
693 |
"nbconvert_exporter": "python", |
|
|
694 |
"pygments_lexer": "ipython3", |
|
|
695 |
"version": "3.5.3" |
|
|
696 |
} |
|
|
697 |
}, |
|
|
698 |
"nbformat": 4, |
|
|
699 |
"nbformat_minor": 2 |
|
|
700 |
} |