From 6981c3b5274eebd5462c29a9e00b11f9c2aa28b4 Mon Sep 17 00:00:00 2001 From: Jaime Ferrando Huertas Date: Wed, 6 May 2020 21:51:55 +0200 Subject: [PATCH] recommit --- README.md | 607 +++++++++++++++++++++++------------------------ requirements.txt | 44 ++-- 2 files changed, 322 insertions(+), 329 deletions(-) diff --git a/README.md b/README.md index 27f96b9..152a9e9 100644 --- a/README.md +++ b/README.md @@ -1,307 +1,300 @@ -# :hourglass_flowing_sand: time-series-forecasting-wiki -This repository contains a series of analysis, transforms and forecasting models frequently used when dealing with time series. The aim of this repository is to showcase how to model time series from the scratch, for this we are using a real usecase dataset ([Beijing air polution dataset](https://archive.ics.uci.edu/ml/datasets/Beijing+PM2.5+Data) to avoid perfect use cases far from reality that are often present in this types of tutorials. If you want to rerun the notebooks make sure you install al neccesary dependencies, [Guide](docs/setup.md) - - - -A simplified table of contents is: - -#PLACEHOLDER - -You can find the more detailed toc on the main notebook #LINK - -**Who is this tutorial aimed to or prerequisites** - -##TOFILL - - - - -# :open_file_folder: Dataset - -The dataset used is the [Beijing air quality](https://archive.ics.uci.edu/ml/datasets/Beijing+PM2.5+Data) public dataset. This dataset contains polution data from 2014 to 2019 sampled every 10 minutes along with extra weather features such as preassure, temperature etc. We decided to resample the dataset with daily frequency for both easier data handling and proximity to a real use case scenario (no one would build a model to predict polution 10 minutes ahead, 1 day ahead looks more realistic). In this case the series is already stationary with some small seasonalities which change every year #MORE ONTHIS - -In order to obtain a exact copy of the dataset used in this tutorial please run the [script](https://github.com/jiwidi/time-series-forecasting-wiki/blob/master/datasets/download_datasets.py) under `datasets/download_datasets.py` which will automatically download the dataset and preprocess it for you. - -# 📚 Analysis and transforms - -* Time series decomposition - * Level - * Trend - * Seasonality - * Noise - -* Stationarity - * AC and PAC plots - * Rolling mean and std - * Dickey-Fuller test - -* Making our time series stationary - * Difference transform - * Log scale - * Smoothing - * Moving average - -# :triangular_ruler: Models tested - -* Autoregression ([AR](https://www.statsmodels.org/stable/generated/statsmodels.tsa.ar_model.AR.html)) -* Moving Average (MA) -* Autoregressive Moving Average (ARMA) -* Autoregressive integraded moving average (ARIMA) -* Seasonal autoregressive integrated moving average (SARIMA) -* Bayesian regression [Link](https://scikit-learn.org/stable/auto_examples/linear_model/plot_bayesian_ridge.html) -* Lasso [Link](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.Lasso.html) -* SVM [Link](https://scikit-learn.org/stable/modules/classes.html?highlight=svm#module-sklearn.svm) -* Randomforest [Link](https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestRegressor.html?highlight=randomforest#sklearn.ensemble.RandomForestRegressor) -* Nearest neighbors [Link](https://scikit-learn.org/stable/modules/neighbors.html) -* XGBoost [Link](https://xgboost.readthedocs.io/en/latest/) -* Lightgbm [Link](https://github.com/microsoft/LightGBM) -* Prophet [Link](https://facebook.github.io/prophet/docs/quick_start.html) -* Long short-term memory with tensorflow (LSTM)[Link](https://www.tensorflow.org/) - -* DeepAR - - -# :mag: Forecasting results -We will devide our results wether the extra features columns such as temperature or preassure were used by the model as this is a huge step in metrics and represents two different scenarios. Metrics used were: - -## Evaluation Metrics -* Mean Absolute Error (MAE) -* Mean Absolute Percentage Error (MAPE) -* Root Mean Squared Error (RMSE) -* Coefficient of determination (R2) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
maermsemaper2
EnsembleXG+TF27.96050339.6868240.4386550.762551
EnsembleLIGHT+TF27.90978439.7505900.4351010.761787
EnsembleXG+LIGHT+TF27.76372239.3463660.4510240.766607
EnsembleXG+LIGHT29.61489341.6602600.5201800.738349
Randomforest tunned40.74096353.1515060.9031820.574099
SVM RBF GRID SEARCH38.56560250.3400270.7767790.617963
DeepAR72.528734105.3913130.957377-0.674509
Tensorflow simple LSTM31.40689044.0077150.4663310.708032
Prophet multivariate38.34679150.5021860.7447340.615498
Kneighbors57.04884780.3873361.0829360.025789
SVM RBF40.80889456.0328000.7942240.526672
Lightgbm30.17366042.7452850.5223380.724543
XGBoost31.04309943.1955460.5421450.718709
Randomforest45.83794259.4489431.0292760.467198
Lasso39.23696654.5839980.7090310.550832
BayesianRidge39.24300154.6344770.7078740.550001
Prophet univariate61.53380283.6467321.268213-0.054814
AutoSARIMAX (1, 0, 1),(0, 0, 0, 6)51.29198371.4868380.9125630.229575
SARIMAX51.25048271.3286430.9052780.232981
AutoARIMA (1, 0, 1)47.09685964.8616931.0056440.365759
ARIMA48.24924366.3875261.0616720.335567
ARMA47.09685964.8616931.0056440.365759
MA49.04387566.2016711.0528690.339282
AR47.23804965.3217181.0155930.356730
HWES52.96029374.6717521.1126270.159398
SES52.96029374.6717521.1126270.159398
Yesterdays value52.67495174.5227641.0440500.162749
Naive mean59.32094081.4443601.3213570.000000
- - - - -# :shipit: Additional resources and literature - -## Models not tested but that are gaining popularity -There are several models we have not tried in this tutorials as they come from the academic world and their implementation is not 100% reliable, but is worth mentioning them: - -* Neural basis expansion analysis for interpretable time series forecasting (N-BEATS) | [link](https://arxiv.org/abs/1905.10437) [Code](https://github.com/philipperemy/n-beats) -* ESRRN [link](https://eng.uber.com/m4-forecasting-competition/) [Code](https://github.com/damitkwr/ESRNN-GPU) - - -# -| | | -| - | - | -| Adhikari, R., & Agrawal, R. K. (2013). An introductory study on time series modeling and forecasting | [[1]](https://arxiv.org/ftp/arxiv/papers/1302/1302.6613.pdf)| -| Introduction to Time Series Forecasting With Python | [[2]](https://machinelearningmastery.com/introduction-to-time-series-forecasting-with-python/)| -| Deep Learning for Time Series Forecasting | [[3]](https://machinelearningmastery.com/deep-learning-for-time-series-forecasting/ ) -| The Complete Guide to Time Series Analysis and Forecasting| [[4]](https://towardsdatascience.com/the-complete-guide-to-time-series-analysis-and-forecasting-70d476bfe775)| -| How to Decompose Time Series Data into Trend and Seasonality| [[5]](https://machinelearningmastery.com/decompose-time-series-data-trend-seasonality/) - - -# Contributing -Want to see another model tested? Do you have anything to add or fix? I'll be happy to talk about it! Open an issue/PR :) +# :hourglass_flowing_sand: time-series-forecasting-wiki +This repository contains a series of analysis, transforms and forecasting models frequently used when dealing with time series. The aim of this repository is to showcase how to model time series from the scratch, for this we are using a real usecase dataset ([Beijing air polution dataset](https://archive.ics.uci.edu/ml/datasets/Beijing+PM2.5+Data) to avoid perfect use cases far from reality that are often present in this types of tutorials. If you want to rerun the notebooks make sure you install al neccesary dependencies, [Guide](docs/setup.md) + + + + +You can find the more detailed toc on the main [notebook](time-series-forecasting-tutorial.ipynb) + + + +# :open_file_folder: Dataset + +The dataset used is the [Beijing air quality](https://archive.ics.uci.edu/ml/datasets/Beijing+PM2.5+Data) public dataset. This dataset contains polution data from 2014 to 2019 sampled every 10 minutes along with extra weather features such as preassure, temperature etc. We decided to resample the dataset with daily frequency for both easier data handling and proximity to a real use case scenario (no one would build a model to predict polution 10 minutes ahead, 1 day ahead looks more realistic). In this case the series is already stationary with some small seasonalities which change every year #MORE ONTHIS + +In order to obtain a exact copy of the dataset used in this tutorial please run the [script](https://github.com/jiwidi/time-series-forecasting-wiki/blob/master/datasets/download_datasets.py) under `datasets/download_datasets.py` which will automatically download the dataset and preprocess it for you. + +# 📚 Analysis and transforms + +* Time series decomposition + * Level + * Trend + * Seasonality + * Noise + +* Stationarity + * AC and PAC plots + * Rolling mean and std + * Dickey-Fuller test + +* Making our time series stationary + * Difference transform + * Log scale + * Smoothing + * Moving average + +# :triangular_ruler: Models tested + +* Autoregression ([AR](https://www.statsmodels.org/stable/generated/statsmodels.tsa.ar_model.AR.html)) +* Moving Average (MA) +* Autoregressive Moving Average (ARMA) +* Autoregressive integraded moving average (ARIMA) +* Seasonal autoregressive integrated moving average (SARIMA) +* Bayesian regression [Link](https://scikit-learn.org/stable/auto_examples/linear_model/plot_bayesian_ridge.html) +* Lasso [Link](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.Lasso.html) +* SVM [Link](https://scikit-learn.org/stable/modules/classes.html?highlight=svm#module-sklearn.svm) +* Randomforest [Link](https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestRegressor.html?highlight=randomforest#sklearn.ensemble.RandomForestRegressor) +* Nearest neighbors [Link](https://scikit-learn.org/stable/modules/neighbors.html) +* XGBoost [Link](https://xgboost.readthedocs.io/en/latest/) +* Lightgbm [Link](https://github.com/microsoft/LightGBM) +* Prophet [Link](https://facebook.github.io/prophet/docs/quick_start.html) +* Long short-term memory with tensorflow (LSTM)[Link](https://www.tensorflow.org/) + +* DeepAR + + +# :mag: Forecasting results +We will devide our results wether the extra features columns such as temperature or preassure were used by the model as this is a huge step in metrics and represents two different scenarios. Metrics used were: + +## Evaluation Metrics +* Mean Absolute Error (MAE) +* Mean Absolute Percentage Error (MAPE) +* Root Mean Squared Error (RMSE) +* Coefficient of determination (R2) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
maermsemaper2
EnsembleXG+TF27.96050339.6868240.4386550.762551
EnsembleLIGHT+TF27.90978439.7505900.4351010.761787
EnsembleXG+LIGHT+TF27.76372239.3463660.4510240.766607
EnsembleXG+LIGHT29.61489341.6602600.5201800.738349
Randomforest tunned40.74096353.1515060.9031820.574099
SVM RBF GRID SEARCH38.56560250.3400270.7767790.617963
DeepAR72.528734105.3913130.957377-0.674509
Tensorflow simple LSTM31.40689044.0077150.4663310.708032
Prophet multivariate38.34679150.5021860.7447340.615498
Kneighbors57.04884780.3873361.0829360.025789
SVM RBF40.80889456.0328000.7942240.526672
Lightgbm30.17366042.7452850.5223380.724543
XGBoost31.04309943.1955460.5421450.718709
Randomforest45.83794259.4489431.0292760.467198
Lasso39.23696654.5839980.7090310.550832
BayesianRidge39.24300154.6344770.7078740.550001
Prophet univariate61.53380283.6467321.268213-0.054814
AutoSARIMAX (1, 0, 1),(0, 0, 0, 6)51.29198371.4868380.9125630.229575
SARIMAX51.25048271.3286430.9052780.232981
AutoARIMA (1, 0, 1)47.09685964.8616931.0056440.365759
ARIMA48.24924366.3875261.0616720.335567
ARMA47.09685964.8616931.0056440.365759
MA49.04387566.2016711.0528690.339282
AR47.23804965.3217181.0155930.356730
HWES52.96029374.6717521.1126270.159398
SES52.96029374.6717521.1126270.159398
Yesterdays value52.67495174.5227641.0440500.162749
Naive mean59.32094081.4443601.3213570.000000
+ + + + +# :shipit: Additional resources and literature + +## Models not tested but that are gaining popularity +There are several models we have not tried in this tutorials as they come from the academic world and their implementation is not 100% reliable, but is worth mentioning them: + +* Neural basis expansion analysis for interpretable time series forecasting (N-BEATS) | [link](https://arxiv.org/abs/1905.10437) [Code](https://github.com/philipperemy/n-beats) +* ESRRN [link](https://eng.uber.com/m4-forecasting-competition/) [Code](https://github.com/damitkwr/ESRNN-GPU) + + +# +| | | +| - | - | +| Adhikari, R., & Agrawal, R. K. (2013). An introductory study on time series modeling and forecasting | [[1]](https://arxiv.org/ftp/arxiv/papers/1302/1302.6613.pdf)| +| Introduction to Time Series Forecasting With Python | [[2]](https://machinelearningmastery.com/introduction-to-time-series-forecasting-with-python/)| +| Deep Learning for Time Series Forecasting | [[3]](https://machinelearningmastery.com/deep-learning-for-time-series-forecasting/ ) +| The Complete Guide to Time Series Analysis and Forecasting| [[4]](https://towardsdatascience.com/the-complete-guide-to-time-series-analysis-and-forecasting-70d476bfe775)| +| How to Decompose Time Series Data into Trend and Seasonality| [[5]](https://machinelearningmastery.com/decompose-time-series-data-trend-seasonality/) + + +# Contributing +Want to see another model tested? Do you have anything to add or fix? I'll be happy to talk about it! Open an issue/PR :) + diff --git a/requirements.txt b/requirements.txt index f54f1cb..5e8c915 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,23 +1,23 @@ -tqdm==4.43 -pydantic==1.4 -requests==2.23 -xgboost==0.90 -fbprophet==0.4 -lightgbm==2.3.1 -bayesian-optimization==1.1 -pandas==0.25 -holidays==0.9.8 -python-dateutil==2.8.0 -numpy==1.16 -scipy==1.4.1 -mxnet==1.4.1 -gluonts==0.4.2 -tensorflow==2.0 -scikit-learn>=0.22 -matplotlib==3.2 -statsmodels==0.11 -beautifultable -tabulate==0.8.3 -pmdarima==1.3 -shap==0.35 +tqdm==4.43 +pydantic==1.4 +requests==2.23 +xgboost==0.90 +fbprophet==0.4 +lightgbm==2.3.1 +bayesian-optimization==1.1 +pandas==0.25 +holidays==0.9.8 +python-dateutil==2.8.0 +numpy==1.16 +scipy==1.4.1 +mxnet==1.4.1 +gluonts==0.4.2 +tensorflow==2.0.1 +scikit-learn>=0.22 +matplotlib==3.2 +statsmodels==0.11 +beautifultable +tabulate==0.8.3 +pmdarima==1.3 +shap==0.35 Jinja2==2.11 \ No newline at end of file