From: Benjamin Auder Date: Thu, 16 Feb 2017 14:24:25 +0000 (+0100) Subject: update report: no memory on average X-Git-Url: https://git.auder.net/game/current/%7B%7B%20asset%28%27mixstore/css/user/common.css%27%29%20%7D%7D?a=commitdiff_plain;h=1b25210ff672f0fc1abf5e91815bb9926e005e27;p=talweg.git update report: no memory on average --- diff --git a/reports/report_2017-03-01.ipynb b/reports/report_2017-03-01.ipynb index bd2e25e..acbdfd0 100644 --- a/reports/report_2017-03-01.ipynb +++ b/reports/report_2017-03-01.ipynb @@ -53,7 +53,7 @@ "indices = seq(as.Date(\"2015-01-18\"),as.Date(\"2015-01-24\"),\"days\")\n", "p_ch_nn = getForecast(data,indices,\"Neighbors\",\"Neighbors\",simtype=\"mix\",same_season=FALSE,mix_strategy=\"mult\")\n", "p_ch_pz = getForecast(data, indices, \"Persistence\", \"Zero\", same_day=TRUE)\n", - "p_ch_az = getForecast(data, indices, \"Average\", \"Zero\", memory=183)\n", + "p_ch_az = getForecast(data, indices, \"Average\", \"Zero\") #, memory=183)\n", "#p_ch_zz = getForecast(data, indices, \"Zero\", \"Zero\")\n", "#p_ch_l = getForecast(data, indices, \"Level\", same_day=FALSE)" ] @@ -181,7 +181,7 @@ "indices = seq(as.Date(\"2015-03-15\"),as.Date(\"2015-03-21\"),\"days\")\n", "p_ep_nn = getForecast(data,indices,\"Neighbors\",\"Neighbors\",simtype=\"mix\",same_season=FALSE,mix_strategy=\"mult\")\n", "p_ep_pz = getForecast(data, indices, \"Persistence\", \"Zero\", same_day=TRUE)\n", - "p_ep_az = getForecast(data, indices, \"Average\", \"Zero\", memory=183)\n", + "p_ep_az = getForecast(data, indices, \"Average\", \"Zero\") #, memory=183)\n", "#p_ep_zz = getForecast(data, indices, \"Zero\", \"Zero\")\n", "#p_ep_l = getForecast(data, indices, \"Level\", same_day=TRUE)" ] @@ -223,7 +223,9 @@ "par(mfrow=c(1,2))\n", "options(repr.plot.width=9, repr.plot.height=4)\n", "plotPredReal(data, p_ep_nn, 4)\n", - "plotPredReal(data, p_ep_nn, 6)" + "plotPredReal(data, p_ep_nn, 6)\n", + "\n", + "#Bleu: prévue, noir: réalisée" ] }, { @@ -284,7 +286,7 @@ "indices = seq(as.Date(\"2015-04-26\"),as.Date(\"2015-05-02\"),\"days\")\n", "p_np_nn = getForecast(data,indices,\"Neighbors\",\"Neighbors\",simtype=\"mix\",same_season=FALSE,mix_strategy=\"mult\")\n", "p_np_pz = getForecast(data, indices, \"Persistence\", \"Zero\", same_day=FALSE)\n", - "p_np_az = getForecast(data, indices, \"Average\", \"Zero\", memory=183)\n", + "p_np_az = getForecast(data, indices, \"Average\", \"Zero\") #, memory=183)\n", "#p_np_zz = getForecast(data, indices, \"Zero\", \"Zero\")\n", "#p_np_l = getForecast(data, indices, \"Level\", same_day=FALSE)" ] @@ -326,7 +328,9 @@ "par(mfrow=c(1,2))\n", "options(repr.plot.width=9, repr.plot.height=4)\n", "plotPredReal(data, p_np_nn, 3)\n", - "plotPredReal(data, p_np_nn, 6)" + "plotPredReal(data, p_np_nn, 6)\n", + "\n", + "#Bleu: prévue, noir: réalisée" ] }, { @@ -336,6 +340,19 @@ "Les \"bonnes\" prédictions (à gauche) sont tout de même trop lissées." ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "par(mfrow=c(1,2))\n", + "plotPredReal(data, p_np_az, 3)\n", + "plotPredReal(data, p_np_az, 6)" + ] + }, { "cell_type": "code", "execution_count": null, diff --git a/reports/report_2017-03-01.nbconvert.ipynb b/reports/report_2017-03-01.nbconvert.ipynb new file mode 100644 index 0000000..bd2e25e --- /dev/null +++ b/reports/report_2017-03-01.nbconvert.ipynb @@ -0,0 +1,409 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "library(talweg)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "data = getData(ts_data=\"../data/pm10_mesures_H_loc.csv\", exo_data=\"../data/meteo_extra_noNAs.csv\",\n", + " input_tz = \"Europe/Paris\", working_tz=\"Europe/Paris\", predict_at=7)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Introduction\n", + "\n", + "J'ai fait quelques essais dans différentes configurations pour la méthode \"Neighbors\" (la seule dont on a parlé).
Il semble que le mieux soit\n", + "\n", + " * simtype=\"mix\" : on utilise les similarités endogènes et exogènes (fenêtre optimisée par VC)\n", + " * same_season=FALSE : les indices pour la validation croisée ne tiennent pas compte des saisons\n", + " * mix_strategy=\"mult\" : on multiplie les poids (au lieu d'en éteindre)\n", + "\n", + "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", + "\n", + "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", + "\n", + "

Pollution par chauffage

" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "indices = seq(as.Date(\"2015-01-18\"),as.Date(\"2015-01-24\"),\"days\")\n", + "p_ch_nn = getForecast(data,indices,\"Neighbors\",\"Neighbors\",simtype=\"mix\",same_season=FALSE,mix_strategy=\"mult\")\n", + "p_ch_pz = getForecast(data, indices, \"Persistence\", \"Zero\", same_day=TRUE)\n", + "p_ch_az = getForecast(data, indices, \"Average\", \"Zero\", memory=183)\n", + "#p_ch_zz = getForecast(data, indices, \"Zero\", \"Zero\")\n", + "#p_ch_l = getForecast(data, indices, \"Level\", same_day=FALSE)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "e_ch_nn = getError(data, p_ch_nn)\n", + "e_ch_pz = getError(data, p_ch_pz)\n", + "e_ch_az = getError(data, p_ch_az)\n", + "#e_ch_zz = getError(data, p_ch_zz)\n", + "#e_ch_l = getError(data, p_ch_l)\n", + "options(repr.plot.width=9, repr.plot.height=6)\n", + "plotError(list(e_ch_nn, e_ch_pz, e_ch_az), cols=c(1,2,colors()[258]))\n", + "\n", + "#Noir: neighbors, rouge: persistence, vert: moyenne" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "La méthode Neighbors fait assez nettement mieux que les autres dans ce cas." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "par(mfrow=c(1,2))\n", + "options(repr.plot.width=9, repr.plot.height=4)\n", + "plotPredReal(data, p_ch_nn, 3)\n", + "plotPredReal(data, p_ch_nn, 4)\n", + "\n", + "#Bleu: prévue, noir: réalisée" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Prédictions d'autant plus lisses que le jour à prévoir est atypique (pollué)." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "par(mfrow=c(1,2))\n", + "plotFilaments(data, p_ch_nn$getIndexInData(3))\n", + "plotFilaments(data, p_ch_nn$getIndexInData(4))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Beaucoup de courbes similaires dans le cas peu pollué, très peu pour un jour pollué." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "par(mfrow=c(1,3))\n", + "plotSimils(p_ch_nn, 3)\n", + "plotSimils(p_ch_nn, 4)\n", + "plotSimils(p_ch_nn, 5)\n", + "\n", + "#Non pollué à gauche, pollué au milieu, autre pollué à droite" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "La plupart des poids très proches de zéro ; pas pour le jour 5 : autre type de jour, cf. ci-dessous." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "par(mfrow=c(1,2))\n", + "plotPredReal(data, p_ch_nn, 5)\n", + "plotFilaments(data, p_ch_nn$getIndexInData(5))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "

Pollution par épandage

" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "indices = seq(as.Date(\"2015-03-15\"),as.Date(\"2015-03-21\"),\"days\")\n", + "p_ep_nn = getForecast(data,indices,\"Neighbors\",\"Neighbors\",simtype=\"mix\",same_season=FALSE,mix_strategy=\"mult\")\n", + "p_ep_pz = getForecast(data, indices, \"Persistence\", \"Zero\", same_day=TRUE)\n", + "p_ep_az = getForecast(data, indices, \"Average\", \"Zero\", memory=183)\n", + "#p_ep_zz = getForecast(data, indices, \"Zero\", \"Zero\")\n", + "#p_ep_l = getForecast(data, indices, \"Level\", same_day=TRUE)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "e_ep_nn = getError(data, p_ep_nn)\n", + "e_ep_pz = getError(data, p_ep_pz)\n", + "e_ep_az = getError(data, p_ep_az)\n", + "#e_ep_zz = getError(data, p_ep_zz)\n", + "#e_ep_l = getError(data, p_ep_l)\n", + "options(repr.plot.width=9, repr.plot.height=6)\n", + "plotError(list(e_ep_nn, e_ep_pz, e_ep_az), cols=c(1,2,colors()[258]))\n", + "\n", + "#Noir: neighbors, rouge: persistence, vert: moyenne" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Cette fois les deux méthodes naïves font en moyenne moins d'erreurs que Neighbors. Prédiction trop difficile ?" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "par(mfrow=c(1,2))\n", + "options(repr.plot.width=9, repr.plot.height=4)\n", + "plotPredReal(data, p_ep_nn, 4)\n", + "plotPredReal(data, p_ep_nn, 6)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "À gauche un jour \"bien\" prévu, à droite le pic d'erreur (jour 6)." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "par(mfrow=c(1,2))\n", + "plotFilaments(data, p_ep_nn$getIndexInData(4))\n", + "plotFilaments(data, p_ep_nn$getIndexInData(6))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "par(mfrow=c(1,2))\n", + "plotSimils(p_ep_nn, 4)\n", + "plotSimils(p_ep_nn, 6)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Même observation concernant les poids : concentrés près de zéro pour les prédictions avec peu de voisins." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Semaine non polluée" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "indices = seq(as.Date(\"2015-04-26\"),as.Date(\"2015-05-02\"),\"days\")\n", + "p_np_nn = getForecast(data,indices,\"Neighbors\",\"Neighbors\",simtype=\"mix\",same_season=FALSE,mix_strategy=\"mult\")\n", + "p_np_pz = getForecast(data, indices, \"Persistence\", \"Zero\", same_day=FALSE)\n", + "p_np_az = getForecast(data, indices, \"Average\", \"Zero\", memory=183)\n", + "#p_np_zz = getForecast(data, indices, \"Zero\", \"Zero\")\n", + "#p_np_l = getForecast(data, indices, \"Level\", same_day=FALSE)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "e_np_nn = getError(data, p_np_nn)\n", + "e_np_pz = getError(data, p_np_pz)\n", + "e_np_az = getError(data, p_np_az)\n", + "#e_np_zz = getError(data, p_np_zz)\n", + "#e_np_l = getError(data, p_np_l)\n", + "options(repr.plot.width=9, repr.plot.height=6)\n", + "plotError(list(e_np_nn, e_np_pz, e_np_az), cols=c(1,2,colors()[258]))\n", + "\n", + "#Noir: neighbors, rouge: persistence, vert: moyenne" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Performances des méthodes \"Average\" et \"Neighbors\" comparables ; mauvais résultats pour la persistence." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "par(mfrow=c(1,2))\n", + "options(repr.plot.width=9, repr.plot.height=4)\n", + "plotPredReal(data, p_np_nn, 3)\n", + "plotPredReal(data, p_np_nn, 6)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Les \"bonnes\" prédictions (à gauche) sont tout de même trop lissées." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "par(mfrow=c(1,2))\n", + "plotFilaments(data, p_np_nn$getIndexInData(3))\n", + "plotFilaments(data, p_np_nn$getIndexInData(6))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Jours \"typiques\", donc beaucoup de voisins." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "par(mfrow=c(1,3))\n", + "plotSimils(p_np_nn, 3)\n", + "plotSimils(p_np_nn, 4)\n", + "plotSimils(p_np_nn, 6)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Répartition idéale des poids : quelques uns au-delà de 0.3-0.4, le reste très proche de zéro." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Bilan\n", + "\n", + "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 same_day).\n", + "\n", + "Comment améliorer la méthode ?" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "R", + "language": "R", + "name": "ir" + }, + "language_info": { + "codemirror_mode": "r", + "file_extension": ".r", + "mimetype": "text/x-r-source", + "name": "R", + "pygments_lexer": "r", + "version": "3.3.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}