4 "cell_type": "markdown",
9 "<h2>Introduction</h2>\n",
11 "J'ai fait quelques essais dans différentes configurations pour la méthode \"Neighbors\"\n",
12 "(la seule dont on a parlé).<br>Il semble que le mieux soit\n",
14 " * simtype=\"exo\" ou \"mix\" : similarités exogènes avec/sans endogènes (fenêtre optimisée par VC)\n",
15 " * same_season=FALSE : les indices pour la validation croisée ne tiennent pas compte des saisons\n",
16 " * mix_strategy=\"mult\" : on multiplie les poids (au lieu d'en éteindre)\n",
18 "J'ai systématiquement comparé à une approche naïve : la moyennes des lendemains des jours\n",
19 "\"similaires\" dans tout le passé ; à chaque fois sans prédiction du saut (sauf pour Neighbors :\n",
20 "prédiction basée sur les poids calculés).\n",
22 "Ensuite j'affiche les erreurs, quelques courbes prévues/mesurées, quelques filaments puis les\n",
23 "histogrammes de quelques poids. Concernant les graphes de filaments, la moitié gauche du graphe\n",
24 "correspond aux jours similaires au jour courant, tandis que la moitié droite affiche les\n",
25 "lendemains : ce sont donc les voisinages tels qu'utilisés dans l'algorithme.\n",
31 "execution_count": null,
39 "ts_data = read.csv(system.file(\"extdata\",\"pm10_mesures_H_loc_report.csv\",package=\"talweg\"))\n",
40 "exo_data = read.csv(system.file(\"extdata\",\"meteo_extra_noNAs.csv\",package=\"talweg\"))\n",
41 "data = getData(ts_data, exo_data, input_tz = \"Europe/Paris\", working_tz=\"Europe/Paris\",\n",
42 "\tpredict_at=7) #predict from P+1 to P+H included\n",
44 "indices_ch = seq(as.Date(\"2015-01-18\"),as.Date(\"2015-01-24\"),\"days\")\n",
45 "indices_ep = seq(as.Date(\"2015-03-15\"),as.Date(\"2015-03-21\"),\"days\")\n",
46 "indices_np = seq(as.Date(\"2015-04-26\"),as.Date(\"2015-05-02\"),\"days\")"
50 "cell_type": "markdown",
55 "<h2 style=\"color:blue;font-size:2em\">Pollution par chauffage</h2>"
60 "execution_count": null,
66 "p_nn_exo = computeForecast(data, indices_ch, \"Neighbors\", \"Neighbors\",\n",
67 "\thorizon=3, simtype=\"exo\")\n",
68 "p_nn_mix = computeForecast(data, indices_ch, \"Neighbors\", \"Neighbors\",\n",
69 "\thorizon=3, simtype=\"mix\")\n",
70 "p_az = computeForecast(data, indices_ch, \"Average\", \"Zero\",\n",
72 "p_pz = computeForecast(data, indices_ch, \"Persistence\", \"Zero\",\n",
73 "\thorizon=3, same_day=TRUE)"
78 "execution_count": null,
84 "e_nn_exo = computeError(data, p_nn_exo, 3)\n",
85 "e_nn_mix = computeError(data, p_nn_mix, 3)\n",
86 "e_az = computeError(data, p_az, 3)\n",
87 "e_pz = computeError(data, p_pz, 3)\n",
88 "options(repr.plot.width=9, repr.plot.height=7)\n",
89 "plotError(list(e_nn_mix, e_pz, e_az, e_nn_exo), cols=c(1,2,colors()[258], 4))\n",
91 "# Noir: neighbors_mix, bleu: neighbors_exo, vert: moyenne, rouge: persistence\n",
93 "i_np = which.min(e_nn_exo$abs$indices)\n",
94 "i_p = which.max(e_nn_exo$abs$indices)"
99 "execution_count": null,
105 "options(repr.plot.width=9, repr.plot.height=4)\n",
106 "par(mfrow=c(1,2))\n",
108 "plotPredReal(data, p_nn_exo, i_np); title(paste(\"PredReal nn exo day\",i_np))\n",
109 "plotPredReal(data, p_nn_exo, i_p); title(paste(\"PredReal nn exo day\",i_p))\n",
111 "plotPredReal(data, p_nn_mix, i_np); title(paste(\"PredReal nn mix day\",i_np))\n",
112 "plotPredReal(data, p_nn_mix, i_p); title(paste(\"PredReal nn mix day\",i_p))\n",
114 "plotPredReal(data, p_az, i_np); title(paste(\"PredReal az day\",i_np))\n",
115 "plotPredReal(data, p_az, i_p); title(paste(\"PredReal az day\",i_p))\n",
117 "# Bleu: prévue, noir: réalisée"
122 "execution_count": null,
128 "par(mfrow=c(1,2))\n",
129 "f_np_exo = computeFilaments(data, p_nn_exo, i_np, plot=TRUE); title(paste(\"Filaments nn exo day\",i_np))\n",
130 "f_p_exo = computeFilaments(data, p_nn_exo, i_p, plot=TRUE); title(paste(\"Filaments nn exo day\",i_p))\n",
132 "f_np_mix = computeFilaments(data, p_nn_mix, i_np, plot=TRUE); title(paste(\"Filaments nn mix day\",i_np))\n",
133 "f_p_mix = computeFilaments(data, p_nn_mix, i_p, plot=TRUE); title(paste(\"Filaments nn mix day\",i_p))"
138 "execution_count": null,
144 "par(mfrow=c(1,2))\n",
145 "plotFilamentsBox(data, f_np_exo); title(paste(\"FilBox nn exo day\",i_np))\n",
146 "plotFilamentsBox(data, f_p_exo); title(paste(\"FilBox nn exo day\",i_p))\n",
148 "plotFilamentsBox(data, f_np_mix); title(paste(\"FilBox nn mix day\",i_np))\n",
149 "plotFilamentsBox(data, f_p_mix); title(paste(\"FilBox nn mix day\",i_p))"
154 "execution_count": null,
160 "par(mfrow=c(1,2))\n",
161 "plotRelVar(data, f_np_exo); title(paste(\"StdDev nn exo day\",i_np))\n",
162 "plotRelVar(data, f_p_exo); title(paste(\"StdDev nn exo day\",i_p))\n",
164 "plotRelVar(data, f_np_mix); title(paste(\"StdDev nn mix day\",i_np))\n",
165 "plotRelVar(data, f_p_mix); title(paste(\"StdDev nn mix day\",i_p))\n",
167 "# Variabilité globale en rouge ; sur les 60 voisins (+ lendemains) en noir"
172 "execution_count": null,
178 "par(mfrow=c(1,2))\n",
179 "plotSimils(p_nn_exo, i_np); title(paste(\"Weights nn exo day\",i_np))\n",
180 "plotSimils(p_nn_exo, i_p); title(paste(\"Weights nn exo day\",i_p))\n",
182 "plotSimils(p_nn_mix, i_np); title(paste(\"Weights nn mix day\",i_np))\n",
183 "plotSimils(p_nn_mix, i_p); title(paste(\"Weights nn mix day\",i_p))\n",
185 "# - pollué à gauche, + pollué à droite"
190 "execution_count": null,
196 "# Fenêtres sélectionnées dans ]0,10] / endo à gauche, exo à droite\n",
197 "p_nn_exo$getParams(i_np)$window\n",
198 "p_nn_exo$getParams(i_p)$window\n",
200 "p_nn_mix$getParams(i_np)$window\n",
201 "p_nn_mix$getParams(i_p)$window"
205 "cell_type": "markdown",
210 "<h2 style=\"color:blue;font-size:2em\">Pollution par épandage</h2>"
215 "execution_count": null,
221 "p_nn_exo = computeForecast(data, indices_ep, \"Neighbors\", \"Neighbors\",\n",
222 "\thorizon=3, simtype=\"exo\")\n",
223 "p_nn_mix = computeForecast(data, indices_ep, \"Neighbors\", \"Neighbors\",\n",
224 "\thorizon=3, simtype=\"mix\")\n",
225 "p_az = computeForecast(data, indices_ep, \"Average\", \"Zero\",\n",
227 "p_pz = computeForecast(data, indices_ep, \"Persistence\", \"Zero\",\n",
228 "\thorizon=3, same_day=TRUE)"
233 "execution_count": null,
239 "e_nn_exo = computeError(data, p_nn_exo, 3)\n",
240 "e_nn_mix = computeError(data, p_nn_mix, 3)\n",
241 "e_az = computeError(data, p_az, 3)\n",
242 "e_pz = computeError(data, p_pz, 3)\n",
243 "options(repr.plot.width=9, repr.plot.height=7)\n",
244 "plotError(list(e_nn_mix, e_pz, e_az, e_nn_exo), cols=c(1,2,colors()[258], 4))\n",
246 "# Noir: neighbors_mix, bleu: neighbors_exo, vert: moyenne, rouge: persistence\n",
248 "i_np = which.min(e_nn_exo$abs$indices)\n",
249 "i_p = which.max(e_nn_exo$abs$indices)"
254 "execution_count": null,
260 "options(repr.plot.width=9, repr.plot.height=4)\n",
261 "par(mfrow=c(1,2))\n",
263 "plotPredReal(data, p_nn_exo, i_np); title(paste(\"PredReal nn exo day\",i_np))\n",
264 "plotPredReal(data, p_nn_exo, i_p); title(paste(\"PredReal nn exo day\",i_p))\n",
266 "plotPredReal(data, p_nn_mix, i_np); title(paste(\"PredReal nn mix day\",i_np))\n",
267 "plotPredReal(data, p_nn_mix, i_p); title(paste(\"PredReal nn mix day\",i_p))\n",
269 "plotPredReal(data, p_az, i_np); title(paste(\"PredReal az day\",i_np))\n",
270 "plotPredReal(data, p_az, i_p); title(paste(\"PredReal az day\",i_p))\n",
272 "# Bleu: prévue, noir: réalisée"
277 "execution_count": null,
283 "par(mfrow=c(1,2))\n",
284 "f_np_exo = computeFilaments(data, p_nn_exo, i_np, plot=TRUE); title(paste(\"Filaments nn exo day\",i_np))\n",
285 "f_p_exo = computeFilaments(data, p_nn_exo, i_p, plot=TRUE); title(paste(\"Filaments nn exo day\",i_p))\n",
287 "f_np_mix = computeFilaments(data, p_nn_mix, i_np, plot=TRUE); title(paste(\"Filaments nn mix day\",i_np))\n",
288 "f_p_mix = computeFilaments(data, p_nn_mix, i_p, plot=TRUE); title(paste(\"Filaments nn mix day\",i_p))"
293 "execution_count": null,
299 "par(mfrow=c(1,2))\n",
300 "plotFilamentsBox(data, f_np_exo); title(paste(\"FilBox nn exo day\",i_np))\n",
301 "plotFilamentsBox(data, f_p_exo); title(paste(\"FilBox nn exo day\",i_p))\n",
303 "plotFilamentsBox(data, f_np_mix); title(paste(\"FilBox nn mix day\",i_np))\n",
304 "plotFilamentsBox(data, f_p_mix); title(paste(\"FilBox nn mix day\",i_p))"
309 "execution_count": null,
315 "par(mfrow=c(1,2))\n",
316 "plotRelVar(data, f_np_exo); title(paste(\"StdDev nn exo day\",i_np))\n",
317 "plotRelVar(data, f_p_exo); title(paste(\"StdDev nn exo day\",i_p))\n",
319 "plotRelVar(data, f_np_mix); title(paste(\"StdDev nn mix day\",i_np))\n",
320 "plotRelVar(data, f_p_mix); title(paste(\"StdDev nn mix day\",i_p))\n",
322 "# Variabilité globale en rouge ; sur les 60 voisins (+ lendemains) en noir"
327 "execution_count": null,
333 "par(mfrow=c(1,2))\n",
334 "plotSimils(p_nn_exo, i_np); title(paste(\"Weights nn exo day\",i_np))\n",
335 "plotSimils(p_nn_exo, i_p); title(paste(\"Weights nn exo day\",i_p))\n",
337 "plotSimils(p_nn_mix, i_np); title(paste(\"Weights nn mix day\",i_np))\n",
338 "plotSimils(p_nn_mix, i_p); title(paste(\"Weights nn mix day\",i_p))\n",
340 "# - pollué à gauche, + pollué à droite"
345 "execution_count": null,
351 "# Fenêtres sélectionnées dans ]0,10] / endo à gauche, exo à droite\n",
352 "p_nn_exo$getParams(i_np)$window\n",
353 "p_nn_exo$getParams(i_p)$window\n",
355 "p_nn_mix$getParams(i_np)$window\n",
356 "p_nn_mix$getParams(i_p)$window"
360 "cell_type": "markdown",
365 "<h2 style=\"color:blue;font-size:2em\">Semaine non polluée</h2>"
370 "execution_count": null,
376 "p_nn_exo = computeForecast(data, indices_np, \"Neighbors\", \"Neighbors\",\n",
377 "\thorizon=3, simtype=\"exo\")\n",
378 "p_nn_mix = computeForecast(data, indices_np, \"Neighbors\", \"Neighbors\",\n",
379 "\thorizon=3, simtype=\"mix\")\n",
380 "p_az = computeForecast(data, indices_np, \"Average\", \"Zero\",\n",
382 "p_pz = computeForecast(data, indices_np, \"Persistence\", \"Zero\",\n",
383 "\thorizon=3, same_day=TRUE)"
388 "execution_count": null,
394 "e_nn_exo = computeError(data, p_nn_exo, 3)\n",
395 "e_nn_mix = computeError(data, p_nn_mix, 3)\n",
396 "e_az = computeError(data, p_az, 3)\n",
397 "e_pz = computeError(data, p_pz, 3)\n",
398 "options(repr.plot.width=9, repr.plot.height=7)\n",
399 "plotError(list(e_nn_mix, e_pz, e_az, e_nn_exo), cols=c(1,2,colors()[258], 4))\n",
401 "# Noir: neighbors_mix, bleu: neighbors_exo, vert: moyenne, rouge: persistence\n",
403 "i_np = which.min(e_nn_exo$abs$indices)\n",
404 "i_p = which.max(e_nn_exo$abs$indices)"
409 "execution_count": null,
415 "options(repr.plot.width=9, repr.plot.height=4)\n",
416 "par(mfrow=c(1,2))\n",
418 "plotPredReal(data, p_nn_exo, i_np); title(paste(\"PredReal nn exo day\",i_np))\n",
419 "plotPredReal(data, p_nn_exo, i_p); title(paste(\"PredReal nn exo day\",i_p))\n",
421 "plotPredReal(data, p_nn_mix, i_np); title(paste(\"PredReal nn mix day\",i_np))\n",
422 "plotPredReal(data, p_nn_mix, i_p); title(paste(\"PredReal nn mix day\",i_p))\n",
424 "plotPredReal(data, p_az, i_np); title(paste(\"PredReal az day\",i_np))\n",
425 "plotPredReal(data, p_az, i_p); title(paste(\"PredReal az day\",i_p))\n",
427 "# Bleu: prévue, noir: réalisée"
432 "execution_count": null,
438 "par(mfrow=c(1,2))\n",
439 "f_np_exo = computeFilaments(data, p_nn_exo, i_np, plot=TRUE); title(paste(\"Filaments nn exo day\",i_np))\n",
440 "f_p_exo = computeFilaments(data, p_nn_exo, i_p, plot=TRUE); title(paste(\"Filaments nn exo day\",i_p))\n",
442 "f_np_mix = computeFilaments(data, p_nn_mix, i_np, plot=TRUE); title(paste(\"Filaments nn mix day\",i_np))\n",
443 "f_p_mix = computeFilaments(data, p_nn_mix, i_p, plot=TRUE); title(paste(\"Filaments nn mix day\",i_p))"
448 "execution_count": null,
454 "par(mfrow=c(1,2))\n",
455 "plotFilamentsBox(data, f_np_exo); title(paste(\"FilBox nn exo day\",i_np))\n",
456 "plotFilamentsBox(data, f_p_exo); title(paste(\"FilBox nn exo day\",i_p))\n",
458 "plotFilamentsBox(data, f_np_mix); title(paste(\"FilBox nn mix day\",i_np))\n",
459 "plotFilamentsBox(data, f_p_mix); title(paste(\"FilBox nn mix day\",i_p))"
464 "execution_count": null,
470 "par(mfrow=c(1,2))\n",
471 "plotRelVar(data, f_np_exo); title(paste(\"StdDev nn exo day\",i_np))\n",
472 "plotRelVar(data, f_p_exo); title(paste(\"StdDev nn exo day\",i_p))\n",
474 "plotRelVar(data, f_np_mix); title(paste(\"StdDev nn mix day\",i_np))\n",
475 "plotRelVar(data, f_p_mix); title(paste(\"StdDev nn mix day\",i_p))\n",
477 "# Variabilité globale en rouge ; sur les 60 voisins (+ lendemains) en noir"
482 "execution_count": null,
488 "par(mfrow=c(1,2))\n",
489 "plotSimils(p_nn_exo, i_np); title(paste(\"Weights nn exo day\",i_np))\n",
490 "plotSimils(p_nn_exo, i_p); title(paste(\"Weights nn exo day\",i_p))\n",
492 "plotSimils(p_nn_mix, i_np); title(paste(\"Weights nn mix day\",i_np))\n",
493 "plotSimils(p_nn_mix, i_p); title(paste(\"Weights nn mix day\",i_p))\n",
495 "# - pollué à gauche, + pollué à droite"
500 "execution_count": null,
506 "# Fenêtres sélectionnées dans ]0,10] / endo à gauche, exo à droite\n",
507 "p_nn_exo$getParams(i_np)$window\n",
508 "p_nn_exo$getParams(i_p)$window\n",
510 "p_nn_mix$getParams(i_np)$window\n",
511 "p_nn_mix$getParams(i_p)$window"
515 "cell_type": "markdown",
522 "Problème difficile : on ne fait guère mieux qu'une naïve moyenne des lendemains des jours\n",
523 "similaires dans le passé, ce qui n'est pas loin de prédire une série constante égale à la\n",
524 "dernière valeur observée (méthode \"zéro\"). La persistence donne parfois de bons résultats\n",
525 "mais est trop instable (sensibilité à l'argument <code>same_day</code>).\n",
527 "Comment améliorer la méthode ?"
538 "codemirror_mode": "r",
539 "file_extension": ".r",
540 "mimetype": "text/x-r-source",
542 "pygments_lexer": "r",