Commit | Line | Data |
---|---|---|
09cf9c19 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": [ | |
56999439 BA |
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", | |
3a3f16cc | 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", |
56999439 BA |
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>" | |
09cf9c19 BA |
43 | ] |
44 | }, | |
45 | { | |
46 | "cell_type": "code", | |
47 | "execution_count": null, | |
48 | "metadata": { | |
49 | "collapsed": false | |
50 | }, | |
51 | "outputs": [], | |
52 | "source": [ | |
e030a6e3 BA |
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", | |
e5aa669a | 55 | "p_ch_pz = getForecast(data, indices, \"Persistence\", \"Zero\", same_day=TRUE)\n", |
3a3f16cc BA |
56 | "p_ch_az = getForecast(data, indices, \"Average\", \"Zero\", memory=183)\n", |
57 | "#p_ch_zz = getForecast(data, indices, \"Zero\", \"Zero\")\n", | |
e5aa669a | 58 | "#p_ch_l = getForecast(data, indices, \"Level\", same_day=FALSE)" |
09cf9c19 BA |
59 | ] |
60 | }, | |
61 | { | |
62 | "cell_type": "code", | |
63 | "execution_count": null, | |
64 | "metadata": { | |
65 | "collapsed": false | |
66 | }, | |
67 | "outputs": [], | |
68 | "source": [ | |
e030a6e3 BA |
69 | "e_ch_nn = getError(data, p_ch_nn)\n", |
70 | "e_ch_pz = getError(data, p_ch_pz)\n", | |
3a3f16cc BA |
71 | "e_ch_az = getError(data, p_ch_az, memory=183)\n", |
72 | "#e_ch_zz = getError(data, p_ch_zz)\n", | |
e5aa669a | 73 | "#e_ch_l = getError(data, p_ch_l)\n", |
09cf9c19 | 74 | "options(repr.plot.width=9, repr.plot.height=6)\n", |
3a3f16cc | 75 | "plotError(list(e_ch_nn, e_ch_pz, e_ch_az), cols=c(1,2,colors()[258]))\n", |
56999439 | 76 | "\n", |
3a3f16cc | 77 | "#Noir: neighbors, rouge: persistence, vert: moyenne" |
56999439 BA |
78 | ] |
79 | }, | |
80 | { | |
81 | "cell_type": "markdown", | |
82 | "metadata": {}, | |
83 | "source": [ | |
e5aa669a | 84 | "La méthode Neighbors fait assez nettement mieux que les autres dans ce cas." |
09cf9c19 BA |
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", | |
56999439 BA |
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é)." | |
09cf9c19 BA |
108 | ] |
109 | }, | |
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 | "plotFilaments(data, p_ch_nn$getIndexInData(3))\n", | |
120 | "plotFilaments(data, p_ch_nn$getIndexInData(4))" | |
121 | ] | |
122 | }, | |
56999439 BA |
123 | { |
124 | "cell_type": "markdown", | |
125 | "metadata": {}, | |
126 | "source": [ | |
127 | "Beaucoup de courbes similaires dans le cas peu pollué, très peu pour un jour pollué." | |
128 | ] | |
129 | }, | |
09cf9c19 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,3))\n", | |
139 | "plotSimils(p_ch_nn, 3)\n", | |
140 | "plotSimils(p_ch_nn, 4)\n", | |
56999439 BA |
141 | "plotSimils(p_ch_nn, 5)\n", |
142 | "\n", | |
143 | "#Non pollué à gauche, pollué au milieu, autre pollué à droite" | |
09cf9c19 BA |
144 | ] |
145 | }, | |
146 | { | |
147 | "cell_type": "markdown", | |
148 | "metadata": {}, | |
149 | "source": [ | |
56999439 BA |
150 | "La plupart des poids très proches de zéro ; pas pour le jour 5 : autre type de jour, cf. ci-dessous." |
151 | ] | |
152 | }, | |
153 | { | |
154 | "cell_type": "code", | |
155 | "execution_count": null, | |
156 | "metadata": { | |
157 | "collapsed": false | |
158 | }, | |
159 | "outputs": [], | |
160 | "source": [ | |
161 | "par(mfrow=c(1,2))\n", | |
162 | "plotPredReal(data, p_ch_nn, 5)\n", | |
163 | "plotFilaments(data, p_ch_nn$getIndexInData(5))" | |
164 | ] | |
165 | }, | |
166 | { | |
167 | "cell_type": "markdown", | |
168 | "metadata": {}, | |
169 | "source": [ | |
170 | "<h2 style=\"color:blue;font-size:2em\">Pollution par épandage</h2>" | |
09cf9c19 BA |
171 | ] |
172 | }, | |
173 | { | |
174 | "cell_type": "code", | |
175 | "execution_count": null, | |
176 | "metadata": { | |
177 | "collapsed": false | |
178 | }, | |
179 | "outputs": [], | |
180 | "source": [ | |
e030a6e3 BA |
181 | "indices = seq(as.Date(\"2015-03-15\"),as.Date(\"2015-03-21\"),\"days\")\n", |
182 | "p_ep_nn = getForecast(data,indices,\"Neighbors\",\"Neighbors\",simtype=\"mix\",same_season=FALSE,mix_strategy=\"mult\")\n", | |
e5aa669a | 183 | "p_ep_pz = getForecast(data, indices, \"Persistence\", \"Zero\", same_day=TRUE)\n", |
3a3f16cc BA |
184 | "p_ep_az = getForecast(data, indices, \"Average\", \"Zero\", memory=183)\n", |
185 | "#p_ep_zz = getForecast(data, indices, \"Zero\", \"Zero\")\n", | |
e5aa669a | 186 | "#p_ep_l = getForecast(data, indices, \"Level\", same_day=TRUE)" |
09cf9c19 BA |
187 | ] |
188 | }, | |
189 | { | |
190 | "cell_type": "code", | |
191 | "execution_count": null, | |
192 | "metadata": { | |
193 | "collapsed": false | |
194 | }, | |
195 | "outputs": [], | |
196 | "source": [ | |
e030a6e3 BA |
197 | "e_ep_nn = getError(data, p_ep_nn)\n", |
198 | "e_ep_pz = getError(data, p_ep_pz)\n", | |
3a3f16cc BA |
199 | "e_ep_az = getError(data, p_ep_az)\n", |
200 | "#e_ep_zz = getError(data, p_ep_zz)\n", | |
e5aa669a | 201 | "#e_ep_l = getError(data, p_ep_l)\n", |
09cf9c19 | 202 | "options(repr.plot.width=9, repr.plot.height=6)\n", |
3a3f16cc | 203 | "plotError(list(e_ep_nn, e_ep_pz, e_ep_az), cols=c(1,2,colors()[258]))\n", |
56999439 | 204 | "\n", |
3a3f16cc | 205 | "#Noir: neighbors, rouge: persistence, vert: moyenne" |
56999439 BA |
206 | ] |
207 | }, | |
208 | { | |
209 | "cell_type": "markdown", | |
210 | "metadata": {}, | |
211 | "source": [ | |
212 | "Cette fois les deux méthodes naïves font en moyenne moins d'erreurs que Neighbors. Prédiction trop difficile ?" | |
09cf9c19 BA |
213 | ] |
214 | }, | |
215 | { | |
216 | "cell_type": "code", | |
217 | "execution_count": null, | |
218 | "metadata": { | |
219 | "collapsed": false | |
220 | }, | |
221 | "outputs": [], | |
222 | "source": [ | |
223 | "par(mfrow=c(1,2))\n", | |
224 | "options(repr.plot.width=9, repr.plot.height=4)\n", | |
56999439 BA |
225 | "plotPredReal(data, p_ep_nn, 4)\n", |
226 | "plotPredReal(data, p_ep_nn, 6)" | |
227 | ] | |
228 | }, | |
229 | { | |
230 | "cell_type": "markdown", | |
231 | "metadata": {}, | |
232 | "source": [ | |
233 | "À gauche un jour \"bien\" prévu, à droite le pic d'erreur (jour 6)." | |
09cf9c19 BA |
234 | ] |
235 | }, | |
236 | { | |
237 | "cell_type": "code", | |
238 | "execution_count": null, | |
239 | "metadata": { | |
240 | "collapsed": false | |
241 | }, | |
242 | "outputs": [], | |
243 | "source": [ | |
244 | "par(mfrow=c(1,2))\n", | |
56999439 BA |
245 | "plotFilaments(data, p_ep_nn$getIndexInData(4))\n", |
246 | "plotFilaments(data, p_ep_nn$getIndexInData(6))" | |
09cf9c19 BA |
247 | ] |
248 | }, | |
249 | { | |
250 | "cell_type": "code", | |
251 | "execution_count": null, | |
252 | "metadata": { | |
253 | "collapsed": false | |
254 | }, | |
255 | "outputs": [], | |
256 | "source": [ | |
56999439 | 257 | "par(mfrow=c(1,2))\n", |
09cf9c19 | 258 | "plotSimils(p_ep_nn, 4)\n", |
56999439 BA |
259 | "plotSimils(p_ep_nn, 6)" |
260 | ] | |
261 | }, | |
262 | { | |
263 | "cell_type": "markdown", | |
264 | "metadata": {}, | |
265 | "source": [ | |
266 | "Même observation concernant les poids : concentrés près de zéro pour les prédictions avec peu de voisins." | |
09cf9c19 BA |
267 | ] |
268 | }, | |
269 | { | |
270 | "cell_type": "markdown", | |
271 | "metadata": {}, | |
272 | "source": [ | |
273 | "## Semaine non polluée" | |
274 | ] | |
275 | }, | |
276 | { | |
277 | "cell_type": "code", | |
278 | "execution_count": null, | |
279 | "metadata": { | |
280 | "collapsed": false | |
281 | }, | |
282 | "outputs": [], | |
283 | "source": [ | |
e030a6e3 BA |
284 | "indices = seq(as.Date(\"2015-04-26\"),as.Date(\"2015-05-02\"),\"days\")\n", |
285 | "p_np_nn = getForecast(data,indices,\"Neighbors\",\"Neighbors\",simtype=\"mix\",same_season=FALSE,mix_strategy=\"mult\")\n", | |
e5aa669a | 286 | "p_np_pz = getForecast(data, indices, \"Persistence\", \"Zero\", same_day=FALSE)\n", |
3a3f16cc BA |
287 | "p_np_az = getForecast(data, indices, \"Average\", \"Zero\", memory=183)\n", |
288 | "#p_np_zz = getForecast(data, indices, \"Zero\", \"Zero\")\n", | |
e5aa669a | 289 | "#p_np_l = getForecast(data, indices, \"Level\", same_day=FALSE)" |
09cf9c19 BA |
290 | ] |
291 | }, | |
292 | { | |
293 | "cell_type": "code", | |
294 | "execution_count": null, | |
295 | "metadata": { | |
296 | "collapsed": false | |
297 | }, | |
298 | "outputs": [], | |
299 | "source": [ | |
e030a6e3 BA |
300 | "e_np_nn = getError(data, p_np_nn)\n", |
301 | "e_np_pz = getError(data, p_np_pz)\n", | |
3a3f16cc BA |
302 | "e_np_az = getError(data, p_np_az)\n", |
303 | "#e_np_zz = getError(data, p_np_zz)\n", | |
e5aa669a | 304 | "#e_np_l = getError(data, p_np_l)\n", |
09cf9c19 | 305 | "options(repr.plot.width=9, repr.plot.height=6)\n", |
3a3f16cc | 306 | "plotError(list(e_np_nn, e_np_pz, e_np_az), cols=c(1,2,colors()[258]))\n", |
56999439 | 307 | "\n", |
3a3f16cc | 308 | "#Noir: neighbors, rouge: persistence, vert: moyenne" |
56999439 BA |
309 | ] |
310 | }, | |
311 | { | |
312 | "cell_type": "markdown", | |
313 | "metadata": {}, | |
314 | "source": [ | |
3a3f16cc | 315 | "Performances des méthodes \"Average\" et \"Neighbors\" comparables ; mauvais résultats pour la persistence." |
09cf9c19 BA |
316 | ] |
317 | }, | |
318 | { | |
319 | "cell_type": "code", | |
320 | "execution_count": null, | |
321 | "metadata": { | |
322 | "collapsed": false | |
323 | }, | |
324 | "outputs": [], | |
325 | "source": [ | |
326 | "par(mfrow=c(1,2))\n", | |
327 | "options(repr.plot.width=9, repr.plot.height=4)\n", | |
328 | "plotPredReal(data, p_np_nn, 3)\n", | |
56999439 BA |
329 | "plotPredReal(data, p_np_nn, 6)" |
330 | ] | |
331 | }, | |
332 | { | |
333 | "cell_type": "markdown", | |
334 | "metadata": {}, | |
335 | "source": [ | |
336 | "Les \"bonnes\" prédictions (à gauche) sont tout de même trop lissées." | |
09cf9c19 BA |
337 | ] |
338 | }, | |
339 | { | |
340 | "cell_type": "code", | |
341 | "execution_count": null, | |
342 | "metadata": { | |
343 | "collapsed": false | |
344 | }, | |
345 | "outputs": [], | |
346 | "source": [ | |
347 | "par(mfrow=c(1,2))\n", | |
348 | "plotFilaments(data, p_np_nn$getIndexInData(3))\n", | |
56999439 BA |
349 | "plotFilaments(data, p_np_nn$getIndexInData(6))" |
350 | ] | |
351 | }, | |
352 | { | |
353 | "cell_type": "markdown", | |
354 | "metadata": {}, | |
355 | "source": [ | |
356 | "Jours \"typiques\", donc beaucoup de voisins." | |
09cf9c19 BA |
357 | ] |
358 | }, | |
359 | { | |
360 | "cell_type": "code", | |
361 | "execution_count": null, | |
362 | "metadata": { | |
363 | "collapsed": false | |
364 | }, | |
365 | "outputs": [], | |
366 | "source": [ | |
367 | "par(mfrow=c(1,3))\n", | |
368 | "plotSimils(p_np_nn, 3)\n", | |
369 | "plotSimils(p_np_nn, 4)\n", | |
56999439 BA |
370 | "plotSimils(p_np_nn, 6)" |
371 | ] | |
372 | }, | |
373 | { | |
374 | "cell_type": "markdown", | |
375 | "metadata": {}, | |
376 | "source": [ | |
377 | "Répartition idéale des poids : quelques uns au-delà de 0.3-0.4, le reste très proche de zéro." | |
378 | ] | |
379 | }, | |
380 | { | |
381 | "cell_type": "markdown", | |
382 | "metadata": {}, | |
383 | "source": [ | |
384 | "## Bilan\n", | |
385 | "\n", | |
3a3f16cc | 386 | "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", |
56999439 BA |
387 | "\n", |
388 | "Comment améliorer la méthode ?" | |
09cf9c19 BA |
389 | ] |
390 | } | |
391 | ], | |
392 | "metadata": { | |
393 | "kernelspec": { | |
394 | "display_name": "R", | |
395 | "language": "R", | |
396 | "name": "ir" | |
397 | }, | |
398 | "language_info": { | |
399 | "codemirror_mode": "r", | |
400 | "file_extension": ".r", | |
401 | "mimetype": "text/x-r-source", | |
402 | "name": "R", | |
403 | "pygments_lexer": "r", | |
404 | "version": "3.3.2" | |
405 | } | |
406 | }, | |
407 | "nbformat": 4, | |
408 | "nbformat_minor": 2 | |
409 | } |