Commit | Line | Data |
---|---|---|
1b25210f BA |
1 | { |
2 | "cells": [ | |
3 | { | |
4 | "cell_type": "code", | |
5 | "execution_count": null, | |
6 | "metadata": { | |
7 | "collapsed": false | |
8 | }, | |
9 | "outputs": [], | |
10 | "source": [ | |
11 | "library(talweg)" | |
12 | ] | |
13 | }, | |
14 | { | |
15 | "cell_type": "code", | |
16 | "execution_count": null, | |
17 | "metadata": { | |
18 | "collapsed": false | |
19 | }, | |
20 | "outputs": [], | |
21 | "source": [ | |
22 | "data = getData(ts_data=\"../data/pm10_mesures_H_loc.csv\", exo_data=\"../data/meteo_extra_noNAs.csv\",\n", | |
23 | " input_tz = \"Europe/Paris\", working_tz=\"Europe/Paris\", predict_at=7)" | |
24 | ] | |
25 | }, | |
26 | { | |
27 | "cell_type": "markdown", | |
28 | "metadata": {}, | |
29 | "source": [ | |
30 | "## Introduction\n", | |
31 | "\n", | |
32 | "J'ai fait quelques essais dans différentes configurations pour la méthode \"Neighbors\" (la seule dont on a parlé).<br>Il semble que le mieux soit\n", | |
33 | "\n", | |
34 | " * simtype=\"mix\" : on utilise les similarités endogènes et exogènes (fenêtre optimisée par VC)\n", | |
35 | " * same_season=FALSE : les indices pour la validation croisée ne tiennent pas compte des saisons\n", | |
36 | " * mix_strategy=\"mult\" : on multiplie les poids (au lieu d'en éteindre)\n", | |
37 | "\n", | |
38 | "J'ai systématiquement comparé à deux autres approches : la persistence et la moyennes des lendemains des jours \"similaires\" dans tout le passé ; à chaque fois sans prédiction du saut (sauf pour Neighbors : prédiction basée sur les poids calculés).\n", | |
39 | "\n", | |
40 | "Ensuite j'affiche les erreurs, quelques courbes prévues/mesurées, quelques filaments puis les histogrammes de quelques poids. Concernant les graphes de filaments, la moitié gauche du graphe correspond aux jours similaires au jour courant, tandis que la moitié droite affiche les lendemains : ce sont donc les voisinages tels qu'utilisés dans l'algorithme.\n", | |
41 | "\n", | |
42 | "<h2 style=\"color:blue;font-size:2em\">Pollution par chauffage</h2>" | |
43 | ] | |
44 | }, | |
45 | { | |
46 | "cell_type": "code", | |
47 | "execution_count": null, | |
48 | "metadata": { | |
49 | "collapsed": false | |
50 | }, | |
51 | "outputs": [], | |
52 | "source": [ | |
53 | "indices = seq(as.Date(\"2015-01-18\"),as.Date(\"2015-01-24\"),\"days\")\n", | |
54 | "p_ch_nn = getForecast(data,indices,\"Neighbors\",\"Neighbors\",simtype=\"mix\",same_season=FALSE,mix_strategy=\"mult\")\n", | |
55 | "p_ch_pz = getForecast(data, indices, \"Persistence\", \"Zero\", same_day=TRUE)\n", | |
4c59ec9a | 56 | "p_ch_az = getForecast(data, indices, \"Average\", \"Zero\") #, memory=183)\n", |
1b25210f BA |
57 | "#p_ch_zz = getForecast(data, indices, \"Zero\", \"Zero\")\n", |
58 | "#p_ch_l = getForecast(data, indices, \"Level\", same_day=FALSE)" | |
59 | ] | |
60 | }, | |
61 | { | |
62 | "cell_type": "code", | |
63 | "execution_count": null, | |
64 | "metadata": { | |
65 | "collapsed": false | |
66 | }, | |
67 | "outputs": [], | |
68 | "source": [ | |
69 | "e_ch_nn = getError(data, p_ch_nn)\n", | |
70 | "e_ch_pz = getError(data, p_ch_pz)\n", | |
71 | "e_ch_az = getError(data, p_ch_az)\n", | |
72 | "#e_ch_zz = getError(data, p_ch_zz)\n", | |
73 | "#e_ch_l = getError(data, p_ch_l)\n", | |
74 | "options(repr.plot.width=9, repr.plot.height=6)\n", | |
75 | "plotError(list(e_ch_nn, e_ch_pz, e_ch_az), cols=c(1,2,colors()[258]))\n", | |
76 | "\n", | |
77 | "#Noir: neighbors, rouge: persistence, vert: moyenne" | |
78 | ] | |
79 | }, | |
80 | { | |
81 | "cell_type": "markdown", | |
82 | "metadata": {}, | |
83 | "source": [ | |
84 | "La méthode Neighbors fait assez nettement mieux que les autres dans ce cas." | |
85 | ] | |
86 | }, | |
87 | { | |
88 | "cell_type": "code", | |
89 | "execution_count": null, | |
90 | "metadata": { | |
91 | "collapsed": false | |
92 | }, | |
93 | "outputs": [], | |
94 | "source": [ | |
95 | "par(mfrow=c(1,2))\n", | |
96 | "options(repr.plot.width=9, repr.plot.height=4)\n", | |
97 | "plotPredReal(data, p_ch_nn, 3)\n", | |
98 | "plotPredReal(data, p_ch_nn, 4)\n", | |
99 | "\n", | |
100 | "#Bleu: prévue, noir: réalisée" | |
101 | ] | |
102 | }, | |
103 | { | |
104 | "cell_type": "markdown", | |
105 | "metadata": {}, | |
106 | "source": [ | |
107 | "Prédictions d'autant plus lisses que le jour à prévoir est atypique (pollué)." | |
108 | ] | |
109 | }, | |
4c59ec9a BA |
110 | { |
111 | "cell_type": "code", | |
112 | "execution_count": null, | |
113 | "metadata": { | |
114 | "collapsed": false | |
115 | }, | |
116 | "outputs": [], | |
117 | "source": [ | |
118 | "par(mfrow=c(1,2))\n", | |
119 | "plotPredReal(data, p_ch_az, 3)\n", | |
120 | "plotPredReal(data, p_ch_az, 4)" | |
121 | ] | |
122 | }, | |
123 | { | |
124 | "cell_type": "markdown", | |
125 | "metadata": {}, | |
126 | "source": [ | |
127 | "Les erreurs sont proches, mais les courbes prédites très différentes : avantage à \"Neighbors\"" | |
128 | ] | |
129 | }, | |
1b25210f BA |
130 | { |
131 | "cell_type": "code", | |
132 | "execution_count": null, | |
133 | "metadata": { | |
134 | "collapsed": false | |
135 | }, | |
136 | "outputs": [], | |
137 | "source": [ | |
138 | "par(mfrow=c(1,2))\n", | |
139 | "plotFilaments(data, p_ch_nn$getIndexInData(3))\n", | |
140 | "plotFilaments(data, p_ch_nn$getIndexInData(4))" | |
141 | ] | |
142 | }, | |
143 | { | |
144 | "cell_type": "markdown", | |
145 | "metadata": {}, | |
146 | "source": [ | |
147 | "Beaucoup de courbes similaires dans le cas peu pollué, très peu pour un jour pollué." | |
148 | ] | |
149 | }, | |
150 | { | |
151 | "cell_type": "code", | |
152 | "execution_count": null, | |
153 | "metadata": { | |
154 | "collapsed": false | |
155 | }, | |
156 | "outputs": [], | |
157 | "source": [ | |
158 | "par(mfrow=c(1,3))\n", | |
159 | "plotSimils(p_ch_nn, 3)\n", | |
160 | "plotSimils(p_ch_nn, 4)\n", | |
161 | "plotSimils(p_ch_nn, 5)\n", | |
162 | "\n", | |
163 | "#Non pollué à gauche, pollué au milieu, autre pollué à droite" | |
164 | ] | |
165 | }, | |
166 | { | |
167 | "cell_type": "markdown", | |
168 | "metadata": {}, | |
169 | "source": [ | |
170 | "La plupart des poids très proches de zéro ; pas pour le jour 5 : autre type de jour, cf. ci-dessous." | |
171 | ] | |
172 | }, | |
173 | { | |
174 | "cell_type": "code", | |
175 | "execution_count": null, | |
176 | "metadata": { | |
177 | "collapsed": false | |
178 | }, | |
179 | "outputs": [], | |
180 | "source": [ | |
181 | "par(mfrow=c(1,2))\n", | |
182 | "plotPredReal(data, p_ch_nn, 5)\n", | |
183 | "plotFilaments(data, p_ch_nn$getIndexInData(5))" | |
184 | ] | |
185 | }, | |
186 | { | |
187 | "cell_type": "markdown", | |
188 | "metadata": {}, | |
189 | "source": [ | |
190 | "<h2 style=\"color:blue;font-size:2em\">Pollution par épandage</h2>" | |
191 | ] | |
192 | }, | |
193 | { | |
194 | "cell_type": "code", | |
195 | "execution_count": null, | |
196 | "metadata": { | |
197 | "collapsed": false | |
198 | }, | |
199 | "outputs": [], | |
200 | "source": [ | |
201 | "indices = seq(as.Date(\"2015-03-15\"),as.Date(\"2015-03-21\"),\"days\")\n", | |
202 | "p_ep_nn = getForecast(data,indices,\"Neighbors\",\"Neighbors\",simtype=\"mix\",same_season=FALSE,mix_strategy=\"mult\")\n", | |
203 | "p_ep_pz = getForecast(data, indices, \"Persistence\", \"Zero\", same_day=TRUE)\n", | |
4c59ec9a | 204 | "p_ep_az = getForecast(data, indices, \"Average\", \"Zero\") #, memory=183)\n", |
1b25210f BA |
205 | "#p_ep_zz = getForecast(data, indices, \"Zero\", \"Zero\")\n", |
206 | "#p_ep_l = getForecast(data, indices, \"Level\", same_day=TRUE)" | |
207 | ] | |
208 | }, | |
209 | { | |
210 | "cell_type": "code", | |
211 | "execution_count": null, | |
212 | "metadata": { | |
213 | "collapsed": false | |
214 | }, | |
215 | "outputs": [], | |
216 | "source": [ | |
217 | "e_ep_nn = getError(data, p_ep_nn)\n", | |
218 | "e_ep_pz = getError(data, p_ep_pz)\n", | |
219 | "e_ep_az = getError(data, p_ep_az)\n", | |
220 | "#e_ep_zz = getError(data, p_ep_zz)\n", | |
221 | "#e_ep_l = getError(data, p_ep_l)\n", | |
222 | "options(repr.plot.width=9, repr.plot.height=6)\n", | |
223 | "plotError(list(e_ep_nn, e_ep_pz, e_ep_az), cols=c(1,2,colors()[258]))\n", | |
224 | "\n", | |
225 | "#Noir: neighbors, rouge: persistence, vert: moyenne" | |
226 | ] | |
227 | }, | |
228 | { | |
229 | "cell_type": "markdown", | |
230 | "metadata": {}, | |
231 | "source": [ | |
232 | "Cette fois les deux méthodes naïves font en moyenne moins d'erreurs que Neighbors. Prédiction trop difficile ?" | |
233 | ] | |
234 | }, | |
235 | { | |
236 | "cell_type": "code", | |
237 | "execution_count": null, | |
238 | "metadata": { | |
239 | "collapsed": false | |
240 | }, | |
241 | "outputs": [], | |
242 | "source": [ | |
243 | "par(mfrow=c(1,2))\n", | |
244 | "options(repr.plot.width=9, repr.plot.height=4)\n", | |
245 | "plotPredReal(data, p_ep_nn, 4)\n", | |
4c59ec9a BA |
246 | "plotPredReal(data, p_ep_nn, 6)\n", |
247 | "\n", | |
248 | "#Bleu: prévue, noir: réalisée" | |
1b25210f BA |
249 | ] |
250 | }, | |
251 | { | |
252 | "cell_type": "markdown", | |
253 | "metadata": {}, | |
254 | "source": [ | |
255 | "À gauche un jour \"bien\" prévu, à droite le pic d'erreur (jour 6)." | |
256 | ] | |
257 | }, | |
4c59ec9a BA |
258 | { |
259 | "cell_type": "code", | |
260 | "execution_count": null, | |
261 | "metadata": { | |
262 | "collapsed": false | |
263 | }, | |
264 | "outputs": [], | |
265 | "source": [ | |
266 | "par(mfrow=c(1,2))\n", | |
267 | "plotPredReal(data, p_ep_pz, 4)\n", | |
268 | "plotPredReal(data, p_ep_pz, 6)" | |
269 | ] | |
270 | }, | |
271 | { | |
272 | "cell_type": "markdown", | |
273 | "metadata": {}, | |
274 | "source": [ | |
275 | "Bonnes performances de la persistence (par chance...)" | |
276 | ] | |
277 | }, | |
1b25210f BA |
278 | { |
279 | "cell_type": "code", | |
280 | "execution_count": null, | |
281 | "metadata": { | |
282 | "collapsed": false | |
283 | }, | |
284 | "outputs": [], | |
285 | "source": [ | |
286 | "par(mfrow=c(1,2))\n", | |
287 | "plotFilaments(data, p_ep_nn$getIndexInData(4))\n", | |
288 | "plotFilaments(data, p_ep_nn$getIndexInData(6))" | |
289 | ] | |
290 | }, | |
291 | { | |
292 | "cell_type": "code", | |
293 | "execution_count": null, | |
294 | "metadata": { | |
295 | "collapsed": false | |
296 | }, | |
297 | "outputs": [], | |
298 | "source": [ | |
299 | "par(mfrow=c(1,2))\n", | |
300 | "plotSimils(p_ep_nn, 4)\n", | |
301 | "plotSimils(p_ep_nn, 6)" | |
302 | ] | |
303 | }, | |
304 | { | |
305 | "cell_type": "markdown", | |
306 | "metadata": {}, | |
307 | "source": [ | |
308 | "Même observation concernant les poids : concentrés près de zéro pour les prédictions avec peu de voisins." | |
309 | ] | |
310 | }, | |
311 | { | |
312 | "cell_type": "markdown", | |
313 | "metadata": {}, | |
314 | "source": [ | |
315 | "## Semaine non polluée" | |
316 | ] | |
317 | }, | |
318 | { | |
319 | "cell_type": "code", | |
320 | "execution_count": null, | |
321 | "metadata": { | |
322 | "collapsed": false | |
323 | }, | |
324 | "outputs": [], | |
325 | "source": [ | |
326 | "indices = seq(as.Date(\"2015-04-26\"),as.Date(\"2015-05-02\"),\"days\")\n", | |
327 | "p_np_nn = getForecast(data,indices,\"Neighbors\",\"Neighbors\",simtype=\"mix\",same_season=FALSE,mix_strategy=\"mult\")\n", | |
328 | "p_np_pz = getForecast(data, indices, \"Persistence\", \"Zero\", same_day=FALSE)\n", | |
4c59ec9a | 329 | "p_np_az = getForecast(data, indices, \"Average\", \"Zero\") #, memory=183)\n", |
1b25210f BA |
330 | "#p_np_zz = getForecast(data, indices, \"Zero\", \"Zero\")\n", |
331 | "#p_np_l = getForecast(data, indices, \"Level\", same_day=FALSE)" | |
332 | ] | |
333 | }, | |
334 | { | |
335 | "cell_type": "code", | |
336 | "execution_count": null, | |
337 | "metadata": { | |
338 | "collapsed": false | |
339 | }, | |
340 | "outputs": [], | |
341 | "source": [ | |
342 | "e_np_nn = getError(data, p_np_nn)\n", | |
343 | "e_np_pz = getError(data, p_np_pz)\n", | |
344 | "e_np_az = getError(data, p_np_az)\n", | |
345 | "#e_np_zz = getError(data, p_np_zz)\n", | |
346 | "#e_np_l = getError(data, p_np_l)\n", | |
347 | "options(repr.plot.width=9, repr.plot.height=6)\n", | |
348 | "plotError(list(e_np_nn, e_np_pz, e_np_az), cols=c(1,2,colors()[258]))\n", | |
349 | "\n", | |
350 | "#Noir: neighbors, rouge: persistence, vert: moyenne" | |
351 | ] | |
352 | }, | |
353 | { | |
354 | "cell_type": "markdown", | |
355 | "metadata": {}, | |
356 | "source": [ | |
357 | "Performances des méthodes \"Average\" et \"Neighbors\" comparables ; mauvais résultats pour la persistence." | |
358 | ] | |
359 | }, | |
360 | { | |
361 | "cell_type": "code", | |
362 | "execution_count": null, | |
363 | "metadata": { | |
364 | "collapsed": false | |
365 | }, | |
366 | "outputs": [], | |
367 | "source": [ | |
368 | "par(mfrow=c(1,2))\n", | |
369 | "options(repr.plot.width=9, repr.plot.height=4)\n", | |
370 | "plotPredReal(data, p_np_nn, 3)\n", | |
4c59ec9a BA |
371 | "plotPredReal(data, p_np_nn, 6)\n", |
372 | "\n", | |
373 | "#Bleu: prévue, noir: réalisée" | |
1b25210f BA |
374 | ] |
375 | }, | |
376 | { | |
377 | "cell_type": "markdown", | |
378 | "metadata": {}, | |
379 | "source": [ | |
380 | "Les \"bonnes\" prédictions (à gauche) sont tout de même trop lissées." | |
381 | ] | |
382 | }, | |
4c59ec9a BA |
383 | { |
384 | "cell_type": "code", | |
385 | "execution_count": null, | |
386 | "metadata": { | |
387 | "collapsed": false | |
388 | }, | |
389 | "outputs": [], | |
390 | "source": [ | |
391 | "par(mfrow=c(1,2))\n", | |
392 | "plotPredReal(data, p_np_az, 3)\n", | |
393 | "plotPredReal(data, p_np_az, 6)" | |
394 | ] | |
395 | }, | |
396 | { | |
397 | "cell_type": "markdown", | |
398 | "metadata": {}, | |
399 | "source": [ | |
400 | "Légèrement meilleur ajustement par la méthode \"Average\" ; très net à droite." | |
401 | ] | |
402 | }, | |
1b25210f BA |
403 | { |
404 | "cell_type": "code", | |
405 | "execution_count": null, | |
406 | "metadata": { | |
407 | "collapsed": false | |
408 | }, | |
409 | "outputs": [], | |
410 | "source": [ | |
411 | "par(mfrow=c(1,2))\n", | |
412 | "plotFilaments(data, p_np_nn$getIndexInData(3))\n", | |
413 | "plotFilaments(data, p_np_nn$getIndexInData(6))" | |
414 | ] | |
415 | }, | |
416 | { | |
417 | "cell_type": "markdown", | |
418 | "metadata": {}, | |
419 | "source": [ | |
420 | "Jours \"typiques\", donc beaucoup de voisins." | |
421 | ] | |
422 | }, | |
423 | { | |
424 | "cell_type": "code", | |
425 | "execution_count": null, | |
426 | "metadata": { | |
427 | "collapsed": false | |
428 | }, | |
429 | "outputs": [], | |
430 | "source": [ | |
431 | "par(mfrow=c(1,3))\n", | |
432 | "plotSimils(p_np_nn, 3)\n", | |
433 | "plotSimils(p_np_nn, 4)\n", | |
434 | "plotSimils(p_np_nn, 6)" | |
435 | ] | |
436 | }, | |
437 | { | |
438 | "cell_type": "markdown", | |
439 | "metadata": {}, | |
440 | "source": [ | |
441 | "Répartition idéale des poids : quelques uns au-delà de 0.3-0.4, le reste très proche de zéro." | |
442 | ] | |
443 | }, | |
444 | { | |
445 | "cell_type": "markdown", | |
446 | "metadata": {}, | |
447 | "source": [ | |
448 | "## Bilan\n", | |
449 | "\n", | |
450 | "Problème difficile : on ne fait guère mieux qu'une naïve moyenne des lendemains des jours similaires dans le passé, ce qui n'est pas loin de prédire une série constante égale à la dernière valeur observée (méthode \"zéro\"). La persistence donne parfois de bons résultats mais est trop instable (sensibilité à l'argument <code>same_day</code>).\n", | |
451 | "\n", | |
452 | "Comment améliorer la méthode ?" | |
453 | ] | |
454 | } | |
455 | ], | |
456 | "metadata": { | |
457 | "kernelspec": { | |
458 | "display_name": "R", | |
459 | "language": "R", | |
460 | "name": "ir" | |
461 | }, | |
462 | "language_info": { | |
463 | "codemirror_mode": "r", | |
464 | "file_extension": ".r", | |
465 | "mimetype": "text/x-r-source", | |
466 | "name": "R", | |
467 | "pygments_lexer": "r", | |
468 | "version": "3.3.2" | |
469 | } | |
470 | }, | |
471 | "nbformat": 4, | |
472 | "nbformat_minor": 2 | |
473 | } |