Python implementations of time series forecasting and anomaly detection

Date

7 October 2022

Topics
Python
forecasting
anomalies
hts
Regular readers will know that I develop statistical models and algorithms, and I write R implementations of them. I’m often asked if there are also Python implementations available. There are.

Nixtla

The best Python implementations for my time series methods are available from Nixtla. Here are some of their packages related to my work, all compatible with scikit-learn.

They have also produced a lot of other great time series tools that are fast (optimized using numba) and perform well compared to various alternatives.

GluonTS

GluonTS from Amazon is excellent and provides lots of probabilistic time series forecasting models, with wrappers to some of my R code, and statsforecast from Nixtla. The other models in GluonTS are also well worth exploring.

Merlion

Merlion from Salesforce is another interesting python library which includes both my automatic ARIMA and automatic ETS algorithms, along with other forecasting methods. It also has some anomaly detection methods for time series.

pmdarima

The first attempt to port my auto.arima() function to Python was pmdarima.

sktime

sktime has the most complete set of time series methods for Python including

and more. These are also compatible with scikit-learn.

Recently, Kate Buchhorn has ported some of my anomaly detection algorithms to Python and made them available in sktime including:

statsmodels

The statsmodels collection includes a few functions based on my work:

pyhts

Bohan Zhang has produced pyhts, a re-implementation of the hts package in Python, based on Hyndman et al. (2011), Hyndman et al. (2016) and Wickramasuriya et al. (2019).

Darts

Darts is a Python library for wrangling and forecasting time series. It includes wrappers for ETS and ARIMA models from statsforecast and pmdarima, as well as an implementation of TBATS and some reconciliation functionality.

References

Assimakopoulos, V., & Nikolopoulos, K. (2000). The theta model: A decomposition approach to forecasting. International Journal of Forecasting, 16(4), 521–530. https://doi.org/10.1016/S0169-2070(00)00066-2
Bandara, K., Hyndman, R. J., & Bergmeir, C. (2022). MSTL: A seasonal-trend decomposition algorithm for time series with multiple seasonal patterns. International J Operational Research. robjhyndman.com/publications/mstl/
Bergmeir, C., Hyndman, R. J., & Benıtez, J. M. (2016). Bagging exponential smoothing methods using STL decomposition and Box-Cox transformation. International Journal of Forecasting, 32(2), 303–312. robjhyndman.com/publications/bagging-ets
De Livera, A. M., Hyndman, R. J., & Snyder, R. D. (2011). Forecasting time series with complex seasonal patterns using exponential smoothing. J American Statistical Association, 106(496), 1513–1527. robjhyndman.com/publications/complex-seasonality/
Hyndman, R. J., Ahmed, R. A., Athanasopoulos, G., & Shang, H. L. (2011). Optimal combination forecasts for hierarchical time series. Computational Statistics & Data Analysis, 55(9), 2579–2589. robjhyndman.com/publications/hierarchical/
Hyndman, R. J., & Billah, M. B. (2003). Unmasking the theta method. International Journal of Forecasting, 19(2), 287–290. robjhyndman.com/publications/unmasking-the-theta-method/
Hyndman, R. J., & Khandakar, Y. (2008). Automatic time series forecasting: The forecast package for R. Journal of Statistical Software, 26(3), 1–22. robjhyndman.com/publications/automatic-forecasting/
Hyndman, R. J., Koehler, A. B., Snyder, R. D., & Grose, S. (2002). A state space framework for automatic forecasting using exponential smoothing methods. International Journal of Forecasting, 18(3), 439–454. robjhyndman.com/publications/hksg/
Hyndman, R. J., Lee, A., & Wang, E. (2016). Fast computation of reconciled forecasts for hierarchical and grouped time series. Computational Statistics & Data Analysis, 97, 16–32.
Hyndman, R. J., & Shang, H. L. (2010). Rainbow plots, bagplots and boxplots for functional data. J Computational & Graphical Statistics, 19(1), 29–45. robjhyndman.com/publications/rainbow-fda
Kandanaarachchi, S., & Hyndman, R. J. (2021). Dimension reduction for outlier detection using DOBIN. J Computational & Graphical Statistics, 30(1), 204–219. robjhyndman.com/publications/dobin
Kang, Y., Hyndman, R. J., & Smith-Miles, K. (2017). Visualising forecasting algorithm performance using time series instance spaces. International Journal of Forecasting, 33(2), 345–358. robjhyndman.com/publications/ts-feature-space/
Montero-Manso, P., Athanasopoulos, G., Hyndman, R. J., & Talagala, T. S. (2020). FFORMA: Feature-based forecast model averaging. International Journal of Forecasting, 36(1), 86–92. robjhyndman.com/publications/fforma/
Shenstone, L., & Hyndman, R. J. (2005). Stochastic models underlying croston’s method for intermittent demand forecasting. Journal of Forecasting, 24(6), 389–402. robjhyndman.com/publications/croston/
Talagala, P. D., Hyndman, R. J., & Smith-Miles, K. (2021). Anomaly detection in high-dimensional data. J Computational & Graphical Statistics, 30(2), 360–374. robjhyndman.com/publications/stray/
Talagala, T. S., Hyndman, R. J., & Athanasopoulos, G. (2018). Meta-learning how to forecast time series (Working Paper No. 6/18). Department of Econometrics & Business Statistics, Monash University. robjhyndman.com/publications/fforms/
Wickramasuriya, S. L., Athanasopoulos, G., & Hyndman, R. J. (2019). Optimal forecast reconciliation for hierarchical and grouped time series through trace minimization. J American Statistical Association, 114(526), 804–819. robjhyndman.com/publications/mint