January 30, 2020

735 words 4 mins read

firmai/atspy

firmai/atspy

Automated Time Series Models in Python (AtsPy)

repo name firmai/atspy
repo link https://github.com/firmai/atspy
homepage
language Python
size (curr.) 725 kB
stars (curr.) 109
created 2020-01-28
license

Automated Time Series Models in Python (AtsPy)

Downloads

Easily develop state of the art time series models to forecast univariate data series. Simply load your data and select which models you want to test. This is the largest repository of automated structural and machine learning time series models. Please get in contact if you want to contribute a model. This is a fledgling project, all advice appreciated.

Install

pip install atspy

Automated Models

  1. ARIMA - Automated ARIMA Modelling
  2. Prophet - Modeling Multiple Seasonality With Linear or Non-linear Growth
  3. HWAAS - Exponential Smoothing With Additive Trend and Additive Seasonality
  4. HWAMS - Exponential Smoothing with Additive Trend and Multiplicative Seasonality
  5. NBEATS - Neural basis expansion analysis (now fixed at 20 Epochs)
  6. Gluonts - RNN-based Model (now fixed at 20 Epochs)
  7. TATS - Seasonal and Trend no Box Cox
  8. TBAT - Trend and Box Cox
  9. TBATS1 - Trend, Seasonal (one), and Box Cox
  10. TBATP1 - TBATS1 but Seasonal Inference is Hardcoded by Periodicity
  11. TBATS2 - TBATS1 With Two Seasonal Periods

Why AtsPy?

  1. Implements all your favourite automated time series models in a unified manner by simply running AutomatedModel(df).
  2. Reduce structural model errors with 30%-50% by using LightGBM with TSFresh infused features.
  3. Automatically identify the seasonalities in your data using singular spectrum analysis, periodograms, and peak analysis.
  4. Identifies and makes accessible the best model for your time series using in-sample validation methods.
  5. Combines the predictions of all these models in a simple (average) and complex (GBM) ensembles for improved performance.
  6. Where appropriate models have been developed to use GPU resources to speed up the automation process.
  7. Easily access all the models by using am.models_dict_in for in-sample and am.models_dict_out for out-of-sample prediction.

AtsPy Progress

  1. Univariate forecasting only (single column) and only monthly and daily data have been tested for suitability.
  2. More work ahead; all suggestions and criticisms appreciated, use the issues tab.
  3. Here is a Google Colab to run the package in the cloud and here you can run all the models.

Documentation by Example


Load Package

from atspy import AutomatedModel

Pandas DataFrame

The data requires strict preprocessing, no periods can be skipped and there cannot be any empty values.

import pandas as pd
df = pd.read_csv("https://raw.githubusercontent.com/firmai/random-assets-two/master/ts/monthly-beer-australia.csv")
df.Month = pd.to_datetime(df.Month)
df = df.set_index("Month"); df

AutomatedModel

  1. AutomatedModel - Returns a class instance.
  2. forecast_insample - Returns an in-sample forcasted dataframe and performance.
  3. forecast_outsample - Returns an out-of-sample forcasted dataframe.
  4. ensemble - Returns the results of three different forms of ensembles.
  5. models_dict_in - Returns a dictionary of the fully trained in-sample models.
  6. models_dict_out - Returns a dictionary of the fully trained out-of-sample models.
from atspy import AutomatedModel
model_list = ["HWAMS","HWAAS","TBAT"]
am = AutomatedModel(df = df , model_list=model_list,forecast_len=20 )

Other models to try, add as many as you like; note ARIMA is slow: ["ARIMA","Gluonts","Prophet","NBEATS", "TATS", "TBATS1", "TBATP1", "TBATS2"]

In-Sample Performance

forecast_in, performance = am.forecast_insample()
performance

Out-of-Sample Forecast

forecast_out = am.forecast_outsample(); forecast_out

Ensemble and Model Validation Performance

all_ensemble_in, all_ensemble_out, all_performance = am.ensemble(forecast_in, forecast_out)
all_performance

Best Performing In-sample

all_ensemble_in[["Target","ensemble_lgb__X__HWAMS","HWAMS","HWAAS"]].plot()

png

Future Predictions All Models

all_ensemble_out[["ensemble_lgb__X__HWAMS","HWAMS","HWAAS"]].plot()

png

And Finally Grab the Models

am.models_dict_in
{'HWAAS': <statsmodels.tsa.holtwinters.HoltWintersResultsWrapper at 0x7f42f7822d30>,
 'HWAMS': <statsmodels.tsa.holtwinters.HoltWintersResultsWrapper at 0x7f42f77fff60>,
 'TBAT': <tbats.tbats.Model.Model at 0x7f42d3aab048>}
am.models_dict_out
{'HWAAS': <statsmodels.tsa.holtwinters.HoltWintersResultsWrapper at 0x7f9c01309278>,
 'HWAMS': <statsmodels.tsa.holtwinters.HoltWintersResultsWrapper at 0x7f9c01309cf8>,
 'TBAT': <tbats.tbats.Model.Model at 0x7f9c08f18ba8>}

Follow this link if you want to run the package in the cloud.

AtsPy Future Development

  1. Additional in-sample validation steps to stop deep learning models from over and underfitting.
  2. Extra performance metrics like MAPE and MAE.
  3. Improved methods to select the window lenght to use in training and calibrating the model.
  4. Add the ability to accept dirty data, and have the ability to clean it up, inetrpolation etc.
  5. Add a function to resample to a larger frequency for big datasets.
  6. Add the ability to algorithmically select a good enough chunk of a large dataset to balance performance and time to train.
  7. More internal model optimisation using AIC, BIC an AICC.
  8. Code annotations for other developers to follow and improve on the work being done.
  9. Force seasonality stability between in and out of sample training models.
  10. Make AtsPy less dependency heavy, currently it draws on tensorflow, pytorch and mxnet.

Citations

If you use AtsPy in your research, please consider citing it.

BibTeX entry:

@software{atspy,
  title = {{AtsPy}: Automated Time Series Models in Python.},
  author = {Snow, Derek},
  url = {https://github.com/firmai/atspy/},
  version = {1.15},
  date = {2020-02-17},
}
comments powered by Disqus