4 "cell_type": "markdown",
12 "<h2>Introduction</h2>\n",
14 "J'ai fait quelques essais dans différentes configurations pour la méthode \"Neighbors\"\n",
15 "(la seule dont on a parlé) et sa variante récente appelée pour l'instant \"Neighbors2\",\n",
16 "avec simtype=\"mix\" : deux types de similarités prises en compte, puis multiplication des poids.\n",
17 "Pour Neighbors on prédit le saut (par la moyenne pondérée des sauts passés), et pour Neighbors2\n",
18 "on n'effectue aucun raccordement (prévision directe).\n",
20 "J'ai systématiquement comparé à une approche naïve : la moyenne des lendemains des jours\n",
21 "\"similaires\" dans tout le passé, ainsi qu'à la persistence -- reproduisant le jour courant ou\n",
22 "allant chercher le futur similaire une semaine avant.\n",
24 "Ensuite j'affiche les erreurs, quelques courbes prévues/mesurées, quelques filaments puis les\n",
25 "histogrammes de quelques poids. Concernant les graphes de filaments, la moitié gauche du graphe\n",
26 "correspond aux jours similaires au jour courant, tandis que la moitié droite affiche les\n",
27 "lendemains : ce sont donc les voisinages tels qu'utilisés dans l'algorithme.\n",
33 "execution_count": null,
43 "P = 7 #instant de prévision\n",
44 "H = 17 #horizon (en heures)\n",
46 "ts_data = read.csv(system.file(\"extdata\",\"pm10_mesures_H_loc_report.csv\",package=\"talweg\"))\n",
47 "exo_data = read.csv(system.file(\"extdata\",\"meteo_extra_noNAs.csv\",package=\"talweg\"))\n",
48 "# NOTE: 'GMT' because DST gaps are filled and multiple values merged in above dataset.\n",
49 "# Prediction from P+1 to P+H included.\n",
50 "data = getData(ts_data, exo_data, input_tz = \"GMT\", working_tz=\"GMT\", predict_at=P)\n",
52 "indices_ch = seq(as.Date(\"2015-01-18\"),as.Date(\"2015-01-24\"),\"days\")\n",
53 "indices_ep = seq(as.Date(\"2015-03-15\"),as.Date(\"2015-03-21\"),\"days\")\n",
54 "indices_np = seq(as.Date(\"2015-04-26\"),as.Date(\"2015-05-02\"),\"days\")\n"
58 "cell_type": "markdown",
66 "<h2 style=\"color:blue;font-size:2em\">Pollution par chauffage</h2>"
71 "execution_count": null,
79 "reload(\"../pkg\")\n",
80 "p_nn = computeForecast(data, indices_ch, \"Neighbors\", \"Neighbors\", horizon=H)\n",
81 "p_nn2 = computeForecast(data, indices_ch, \"Neighbors2\", \"Neighbors\", horizon=H)\n",
82 "p_az = computeForecast(data, indices_ch, \"Average\", \"Zero\", horizon=H)\n",
83 "p_pz = computeForecast(data, indices_ch, \"Persistence\", \"Zero\", horizon=H, same_day=TRUE)"
88 "execution_count": null,
96 "p_nn2$getParams(5)$weights"
101 "execution_count": null,
109 "e_nn = computeError(data, p_nn, H)\n",
110 "e_nn2 = computeError(data, p_nn2, H)\n",
111 "e_az = computeError(data, p_az, H)\n",
112 "e_pz = computeError(data, p_pz, H)\n",
113 "options(repr.plot.width=9, repr.plot.height=7)\n",
114 "plotError(list(e_nn, e_pz, e_az, e_nn2), cols=c(1,2,colors()[258], 4))\n",
116 "# Noir: Neighbors, bleu: Neighbors2, vert: moyenne, rouge: persistence\n",
118 "i_np = which.min(e_nn$abs$indices)\n",
119 "i_p = which.max(e_nn$abs$indices)"
124 "execution_count": null,
132 "options(repr.plot.width=9, repr.plot.height=4)\n",
133 "par(mfrow=c(1,2))\n",
135 "plotPredReal(data, p_nn, i_np); title(paste(\"PredReal nn day\",i_np))\n",
136 "plotPredReal(data, p_nn2, i_p); title(paste(\"PredReal nn day\",i_p))\n",
138 "plotPredReal(data, p_nn2, i_np); title(paste(\"PredReal nn2 day\",i_np))\n",
139 "plotPredReal(data, p_nn2, i_p); title(paste(\"PredReal nn2 day\",i_p))\n",
141 "plotPredReal(data, p_az, i_np); title(paste(\"PredReal az day\",i_np))\n",
142 "plotPredReal(data, p_az, i_p); title(paste(\"PredReal az day\",i_p))\n",
144 "# Bleu: prévue, noir: réalisée"
149 "execution_count": null,
157 "par(mfrow=c(1,2))\n",
158 "f_np = computeFilaments(data, p_nn, i_np, plot=TRUE); title(paste(\"Filaments nn day\",i_np))\n",
159 "f_p = computeFilaments(data, p_nn, i_p, plot=TRUE); title(paste(\"Filaments nn day\",i_p))\n",
161 "f_np2 = computeFilaments(data, p_nn2, i_np, plot=TRUE); title(paste(\"Filaments nn2 day\",i_np))\n",
162 "f_p2 = computeFilaments(data, p_nn2, i_p, plot=TRUE); title(paste(\"Filaments nn2 day\",i_p))"
167 "execution_count": null,
175 "par(mfrow=c(1,2))\n",
176 "#plotFilamentsBox(data, f_np); title(paste(\"FilBox nn day\",i_np))\n",
177 "#plotFilamentsBox(data, f_p); title(paste(\"FilBox nn day\",i_p))\n",
179 "plotFilamentsBox(data, f_np2); title(paste(\"FilBox nn2 day\",i_np))\n",
180 "#plotFilamentsBox(data, f_p2); title(paste(\"FilBox nn2 day\",i_p))"
185 "execution_count": null,
196 "execution_count": null,
204 "par(mfrow=c(1,2))\n",
205 "plotRelVar(data, f_np); title(paste(\"StdDev nn day\",i_np))\n",
206 "plotRelVar(data, f_p); title(paste(\"StdDev nn day\",i_p))\n",
208 "plotRelVar(data, f_np2); title(paste(\"StdDev nn2 day\",i_np))\n",
209 "plotRelVar(data, f_p2); title(paste(\"StdDev nn2 day\",i_p))\n",
211 "# Variabilité globale en rouge ; sur les 60 voisins (+ lendemains) en noir"
216 "execution_count": null,
224 "par(mfrow=c(1,2))\n",
225 "plotSimils(p_nn, i_np); title(paste(\"Weights nn day\",i_np))\n",
226 "plotSimils(p_nn, i_p); title(paste(\"Weights nn day\",i_p))\n",
228 "plotSimils(p_nn2, i_np); title(paste(\"Weights nn2 day\",i_np))\n",
229 "plotSimils(p_nn2, i_p); title(paste(\"Weights nn2 day\",i_p))\n",
231 "# - pollué à gauche, + pollué à droite"
236 "execution_count": null,
244 "# Fenêtres sélectionnées dans ]0,7] / nn à gauche, nn2 à droite\n",
245 "p_nn$getParams(i_np)$window\n",
246 "p_nn$getParams(i_p)$window\n",
248 "p_nn2$getParams(i_np)$window\n",
249 "p_nn2$getParams(i_p)$window"
253 "cell_type": "markdown",
261 "<h2 style=\"color:blue;font-size:2em\">Pollution par épandage</h2>"
266 "execution_count": null,
274 "p_nn = computeForecast(data, indices_ep, \"Neighbors\", \"Neighbors\", horizon=H)\n",
275 "p_nn2 = computeForecast(data, indices_ep, \"Neighbors2\", \"Zero\", horizon=H)\n",
276 "p_az = computeForecast(data, indices_ep, \"Average\", \"Zero\", horizon=H)\n",
277 "p_pz = computeForecast(data, indices_ep, \"Persistence\", \"Zero\", horizon=H, same_day=TRUE)"
282 "execution_count": null,
290 "e_nn = computeError(data, p_nn, H)\n",
291 "e_nn2 = computeError(data, p_nn2, H)\n",
292 "e_az = computeError(data, p_az, H)\n",
293 "e_pz = computeError(data, p_pz, H)\n",
294 "options(repr.plot.width=9, repr.plot.height=7)\n",
295 "plotError(list(e_nn, e_pz, e_az, e_nn2), cols=c(1,2,colors()[258], 4))\n",
297 "# Noir: Neighbors, bleu: Neighbors2, vert: moyenne, rouge: persistence\n",
299 "i_np = which.min(e_nn$abs$indices)\n",
300 "i_p = which.max(e_nn$abs$indices)"
305 "execution_count": null,
313 "options(repr.plot.width=9, repr.plot.height=4)\n",
314 "par(mfrow=c(1,2))\n",
316 "plotPredReal(data, p_nn, i_np); title(paste(\"PredReal nn day\",i_np))\n",
317 "plotPredReal(data, p_nn2, i_p); title(paste(\"PredReal nn day\",i_p))\n",
319 "plotPredReal(data, p_nn2, i_np); title(paste(\"PredReal nn2 day\",i_np))\n",
320 "plotPredReal(data, p_nn2, i_p); title(paste(\"PredReal nn2 day\",i_p))\n",
322 "plotPredReal(data, p_az, i_np); title(paste(\"PredReal az day\",i_np))\n",
323 "plotPredReal(data, p_az, i_p); title(paste(\"PredReal az day\",i_p))\n",
325 "# Bleu: prévue, noir: réalisée"
330 "execution_count": null,
338 "par(mfrow=c(1,2))\n",
339 "f_np = computeFilaments(data, p_nn, i_np, plot=TRUE); title(paste(\"Filaments nn day\",i_np))\n",
340 "f_p = computeFilaments(data, p_nn, i_p, plot=TRUE); title(paste(\"Filaments nn day\",i_p))\n",
342 "f_np2 = computeFilaments(data, p_nn2, i_np, plot=TRUE); title(paste(\"Filaments nn2 day\",i_np))\n",
343 "f_p2 = computeFilaments(data, p_nn2, i_p, plot=TRUE); title(paste(\"Filaments nn2 day\",i_p))"
348 "execution_count": null,
356 "par(mfrow=c(1,2))\n",
357 "plotFilamentsBox(data, f_np); title(paste(\"FilBox nn day\",i_np))\n",
358 "plotFilamentsBox(data, f_p); title(paste(\"FilBox nn day\",i_p))\n",
360 "plotFilamentsBox(data, f_np2); title(paste(\"FilBox nn2 day\",i_np))\n",
361 "plotFilamentsBox(data, f_p2); title(paste(\"FilBox nn2 day\",i_p))"
366 "execution_count": null,
374 "par(mfrow=c(1,2))\n",
375 "plotRelVar(data, f_np); title(paste(\"StdDev nn day\",i_np))\n",
376 "plotRelVar(data, f_p); title(paste(\"StdDev nn day\",i_p))\n",
378 "plotRelVar(data, f_np2); title(paste(\"StdDev nn2 day\",i_np))\n",
379 "plotRelVar(data, f_p2); title(paste(\"StdDev nn2 day\",i_p))\n",
381 "# Variabilité globale en rouge ; sur les 60 voisins (+ lendemains) en noir"
386 "execution_count": null,
394 "par(mfrow=c(1,2))\n",
395 "plotSimils(p_nn, i_np); title(paste(\"Weights nn day\",i_np))\n",
396 "plotSimils(p_nn, i_p); title(paste(\"Weights nn day\",i_p))\n",
398 "plotSimils(p_nn2, i_np); title(paste(\"Weights nn2 day\",i_np))\n",
399 "plotSimils(p_nn2, i_p); title(paste(\"Weights nn2 day\",i_p))\n",
401 "# - pollué à gauche, + pollué à droite"
406 "execution_count": null,
414 "# Fenêtres sélectionnées dans ]0,7] / nn à gauche, nn2 à droite\n",
415 "p_nn$getParams(i_np)$window\n",
416 "p_nn$getParams(i_p)$window\n",
418 "p_nn2$getParams(i_np)$window\n",
419 "p_nn2$getParams(i_p)$window"
423 "cell_type": "markdown",
431 "<h2 style=\"color:blue;font-size:2em\">Semaine non polluée</h2>"
436 "execution_count": null,
444 "p_nn = computeForecast(data, indices_np, \"Neighbors\", \"Neighbors\", horizon=H)\n",
445 "p_nn2 = computeForecast(data, indices_np, \"Neighbors2\", \"Zero\", horizon=H)\n",
446 "p_az = computeForecast(data, indices_np, \"Average\", \"Zero\", horizon=H)\n",
447 "p_pz = computeForecast(data, indices_np, \"Persistence\", \"Zero\", horizon=H, same_day=FALSE)"
452 "execution_count": null,
460 "e_nn = computeError(data, p_nn, H)\n",
461 "e_nn2 = computeError(data, p_nn2, H)\n",
462 "e_az = computeError(data, p_az, H)\n",
463 "e_pz = computeError(data, p_pz, H)\n",
464 "options(repr.plot.width=9, repr.plot.height=7)\n",
465 "plotError(list(e_nn, e_pz, e_az, e_nn2), cols=c(1,2,colors()[258], 4))\n",
467 "# Noir: Neighbors, bleu: Neighbors2, vert: moyenne, rouge: persistence\n",
469 "i_np = which.min(e_nn$abs$indices)\n",
470 "i_p = which.max(e_nn$abs$indices)"
475 "execution_count": null,
483 "options(repr.plot.width=9, repr.plot.height=4)\n",
484 "par(mfrow=c(1,2))\n",
486 "plotPredReal(data, p_nn, i_np); title(paste(\"PredReal nn day\",i_np))\n",
487 "plotPredReal(data, p_nn2, i_p); title(paste(\"PredReal nn day\",i_p))\n",
489 "plotPredReal(data, p_nn2, i_np); title(paste(\"PredReal nn2 day\",i_np))\n",
490 "plotPredReal(data, p_nn2, i_p); title(paste(\"PredReal nn2 day\",i_p))\n",
492 "plotPredReal(data, p_az, i_np); title(paste(\"PredReal az day\",i_np))\n",
493 "plotPredReal(data, p_az, i_p); title(paste(\"PredReal az day\",i_p))\n",
495 "# Bleu: prévue, noir: réalisée"
500 "execution_count": null,
508 "par(mfrow=c(1,2))\n",
509 "f_np = computeFilaments(data, p_nn, i_np, plot=TRUE); title(paste(\"Filaments nn day\",i_np))\n",
510 "f_p = computeFilaments(data, p_nn, i_p, plot=TRUE); title(paste(\"Filaments nn day\",i_p))\n",
512 "f_np2 = computeFilaments(data, p_nn2, i_np, plot=TRUE); title(paste(\"Filaments nn2 day\",i_np))\n",
513 "f_p2 = computeFilaments(data, p_nn2, i_p, plot=TRUE); title(paste(\"Filaments nn2 day\",i_p))"
518 "execution_count": null,
526 "par(mfrow=c(1,2))\n",
527 "plotFilamentsBox(data, f_np); title(paste(\"FilBox nn day\",i_np))\n",
528 "plotFilamentsBox(data, f_p); title(paste(\"FilBox nn day\",i_p))\n",
530 "plotFilamentsBox(data, f_np2); title(paste(\"FilBox nn2 day\",i_np))\n",
531 "plotFilamentsBox(data, f_p2); title(paste(\"FilBox nn2 day\",i_p))"
536 "execution_count": null,
544 "par(mfrow=c(1,2))\n",
545 "plotRelVar(data, f_np); title(paste(\"StdDev nn day\",i_np))\n",
546 "plotRelVar(data, f_p); title(paste(\"StdDev nn day\",i_p))\n",
548 "plotRelVar(data, f_np2); title(paste(\"StdDev nn2 day\",i_np))\n",
549 "plotRelVar(data, f_p2); title(paste(\"StdDev nn2 day\",i_p))\n",
551 "# Variabilité globale en rouge ; sur les 60 voisins (+ lendemains) en noir"
556 "execution_count": null,
564 "par(mfrow=c(1,2))\n",
565 "plotSimils(p_nn, i_np); title(paste(\"Weights nn day\",i_np))\n",
566 "plotSimils(p_nn, i_p); title(paste(\"Weights nn day\",i_p))\n",
568 "plotSimils(p_nn2, i_np); title(paste(\"Weights nn2 day\",i_np))\n",
569 "plotSimils(p_nn2, i_p); title(paste(\"Weights nn2 day\",i_p))\n",
571 "# - pollué à gauche, + pollué à droite"
576 "execution_count": null,
584 "# Fenêtres sélectionnées dans ]0,7] / nn à gauche, nn2 à droite\n",
585 "p_nn$getParams(i_np)$window\n",
586 "p_nn$getParams(i_p)$window\n",
588 "p_nn2$getParams(i_np)$window\n",
589 "p_nn2$getParams(i_p)$window"
600 "codemirror_mode": "r",
601 "file_extension": ".r",
602 "mimetype": "text/x-r-source",
604 "pygments_lexer": "r",