Skip to main content
Open In Colab

Motivation

The AutoARIMA model is widely used to forecast time series in production and as a benchmark. However, the python implementation (pmdarima) is so slow that prevent data scientist practioners from quickly iterating and deploying AutoARIMA in production for a large number of time series. In this notebook we present Nixtla’s AutoARIMA based on the R implementation (developed by Rob Hyndman) and optimized using numba.

Example

Libraries

Useful functions

Data

For testing purposes, we will use the Hourly dataset from the M4 competition.
In this example we will use a subset of the data to avoid waiting too long. You can modify the number of series if you want.
Would an autorregresive model be the right choice for our data? There is no doubt that we observe seasonal periods. The autocorrelation function (acf) can help us to answer the question. Intuitively, we have to observe a decreasing correlation to opt for an AR model.
Thus, we observe a high autocorrelation for previous lags and also for the seasonal lags. Therefore, we will let auto_arima to handle our data.

Training and forecasting

StatsForecast receives a list of models to fit each time series. Since we are dealing with Hourly data, it would be benefitial to use 24 as seasonality.
As we see, we can pass season_length to AutoARIMA, so the definition of our models would be,
dsAutoARIMA
unique_id
H1701616.084167
H1702544.432129
H1703510.414490
H1704481.046539
H1705460.893066

Alternatives

pmdarima

You can use the StatsForecast class to parallelize your own models. In this section we will use it to run the auto_arima model from pmdarima.
dspmdarima
unique_id
H1701628.310547
H1702571.659851
H1703543.504700
H1704517.539062
H1705502.829559

Prophet

Prophet is designed to receive a pandas dataframe, so we cannot use StatForecast. Therefore, we need to parallize from scratch.
unique_iddsprophet
0H1701635.914254
1H1702565.976464
2H1703505.095507
3H1704462.559539
4H1705438.766801
43H1127446184.686240
44H1127456188.851888
45H1127466129.306256
46H1127476058.040672
47H1127485991.982370

Evaluation

Time

Since AutoARIMA works with numba is useful to calculate the time for just one time series.
pmdarimaprophetAutoARIMA_nixtla
n_series
410181686.7580593093.636144573.128222
411182129.8964943101.181598574.480358
412182573.0349283108.727052575.832494
413183016.1733623116.272506577.184630
414183459.3117963123.817960578.536766

Performance

pmdarima (only two time series)

modelmae
0AutoARIMA20.289669
1pmdarima24.676279
2prophet39.201933

Prophet

modelmae
0AutoARIMA680.202965
1prophet1058.578963
For a complete comparison check the complete experiment. Open In Colab