0
$\begingroup$

A cordial greeting to all. I am working with a time series and I am trying to predict it with SARIMAX.

As there are many variations to adjust the values of the variables order (p, d, q) and seasonal_order (P, D, Q, s).

I found the pmdarima library, with its auto_arima function it automatically discover the optimal order for an ARIMA model. I am looking for something similar for SARIMAX.

I was wondering, is there a library that calculates the values of the order and seasonal_order variables automatically? to get the best result.

I appreciate the help you can give me in this regard. Thanks.

$\endgroup$

2 Answers 2

0
$\begingroup$

Doctor Jason Brownlee, on his page https://machinelearningmastery.com. I publish code in python that can serve you, it is not a library as such, but perhaps it will serve as a palliative to what you are looking for.

You could also extrapolate this idea (it is used in SARIMA), but with some changes and calculation of the error it could be useful.

In section, SARIMA to time series forecasting, You modify part of the code and it should look like this:

p = d = q = P = D = Q = s = range(0, 2)
pdqPDQs = list(itertools.product(p, d, q, P, D, Q, s))

Here you will find experts on the subject, they will certainly be able to help you with what you are looking for.

$\endgroup$
0
$\begingroup$

The implementation is called SARIMAX instead of SARIMA because the “X” addition to the method name means that the implementation also supports exogenous variables.

These are parallel time series variates that are not modeled directly via AR, I, or MA processes, but are made available as a weighted input to the model.

Exogenous variables are optional can be specified via the “exog” argument.

So they both have the same base (in essence).

How to Configure SARIMA

Configuring a SARIMA requires selecting hyperparameters for both the trend and seasonal elements of the series.

Trend Elements

There are three trend elements that require configuration.

They are the same as the ARIMA model; specifically:

  • p: Trend autoregression order.
  • d: Trend difference order.
  • q: Trend moving average order.

Seasonal Elements

There are four seasonal elements that are not part of ARIMA that must be configured; they are:

  • P: Seasonal autoregressive order.
  • D: Seasonal difference order.
  • Q: Seasonal moving average order.
  • m: The number of time steps for a single seasonal period.

Knowing this in advance ... you can use the package pmdarima

import numpy as np
import pandas as pd
from pmdarima import auto_arima

datos = [21.5294, 21.5228, 21.5289, 21.5096, 21.506, 21.5119, 21.5173, 21.5308, 21.5355, 21.5181, 21.5, 21.4972, 21.5067, 21.5149, 21.4994, 21.4967, 21.4774, 21.4662, 21.4752, 21.4858, 21.4581, 21.4398, 21.4385, 21.4471, 21.4399, 21.444, 21.4555, 21.4366, 21.4402, 21.4371, 21.4317, 21.4342, 21.411, 21.4174, 21.4149, 21.4151, 21.4186, 21.4411, 21.4569, 21.4628, 21.448, 21.4468, 21.4357, 21.4329, 21.4543, 21.4429, 21.4478, 21.4423, 21.4536, 21.4416, 21.4384, 21.4378, 21.4622, 21.4413, 21.4315, 21.4419, 21.4323, 21.429, 21.4103, 21.4194, 21.4364, 21.4245, 21.4348, 21.4276, 21.4113, 21.4235, 21.407, 21.412, 21.4263, 21.431, 21.4362, 21.432, 21.4445, 21.4487, 21.4623, 21.4766, 21.4785, 21.4891, 21.4869, 21.4903, 21.4839, 21.4856, 21.4909, 21.5048, 21.5005, 21.4905, 21.4906, 21.4914, 21.5052, 21.4898, 21.5232, 21.5234, 21.5086, 21.5108, 21.5017, 21.5141, 21.5055, 21.4953, 21.4618, 21.4504, 21.4667, 21.4602, 21.453, 21.4497, 21.4446, 21.4308, 21.4347, 21.4512, 21.4675, 21.4675, 21.465, 21.4624, 21.4682, 21.472, 21.4632, 21.4644, 21.4615, 21.4604, 21.4679, 21.4672]

indice = pd.date_range("2020-10-31 23:57:00", periods=len(datos), freq="T")

Data = pd.Series(data=datos, index=indice)
        
Data = datos.asfreq(freq='T')
   

model_fit = auto_arima(Data, start_p=0, max_p=6, start_q=0, max_q=3, seasonal=False, trace=True)

model_fit.summary()

You will get the following result...

Performing stepwise search to minimize aic
 ARIMA(0,0,0)(0,0,0)[0]             : AIC=1078.473, Time=0.01 sec
 ARIMA(1,0,0)(0,0,0)[0]             : AIC=inf, Time=0.18 sec
 ARIMA(0,0,1)(0,0,0)[0]             : AIC=inf, Time=0.11 sec
 ARIMA(1,0,1)(0,0,0)[0]             : AIC=-707.310, Time=0.22 sec
 ARIMA(2,0,1)(0,0,0)[0]             : AIC=inf, Time=0.68 sec
 ARIMA(1,0,2)(0,0,0)[0]             : AIC=-653.211, Time=0.27 sec
 ARIMA(0,0,2)(0,0,0)[0]             : AIC=inf, Time=0.19 sec
 ARIMA(2,0,0)(0,0,0)[0]             : AIC=inf, Time=0.16 sec
 ARIMA(2,0,2)(0,0,0)[0]             : AIC=-678.058, Time=0.47 sec
 ARIMA(1,0,1)(0,0,0)[0] intercept   : AIC=-720.672, Time=1.13 sec
 ARIMA(0,0,1)(0,0,0)[0] intercept   : AIC=-590.239, Time=0.17 sec
 ARIMA(1,0,0)(0,0,0)[0] intercept   : AIC=-722.662, Time=0.14 sec
 ARIMA(0,0,0)(0,0,0)[0] intercept   : AIC=-475.518, Time=0.06 sec
 ARIMA(2,0,0)(0,0,0)[0] intercept   : AIC=-720.684, Time=0.16 sec
 ARIMA(2,0,1)(0,0,0)[0] intercept   : AIC=-719.641, Time=0.58 sec



                               SARIMAX Results                                
==============================================================================
Dep. Variable:                      y   No. Observations:                  120
Model:               SARIMAX(1, 0, 0)   Log Likelihood                 364.331
Date:                Sat, 10 Jul 2021   AIC                           -722.662
Time:                        21:27:20   BIC                           -714.299
Sample:                             0   HQIC                          -719.266
                                - 120                                         
Covariance Type:                  opg                                         
==============================================================================
                 coef    std err          z      P>|z|      [0.025      0.975]
------------------------------------------------------------------------------
intercept      1.6975      0.648      2.618      0.009       0.427       2.968
ar.L1          0.9209      0.030     30.503      0.000       0.862       0.980
sigma2         0.0001   1.72e-05      7.758      0.000    9.95e-05       0.000
===================================================================================
Ljung-Box (L1) (Q):                   0.02   Jarque-Bera (JB):                 0.03
Prob(Q):                              0.88   Prob(JB):                         0.99
Heteroskedasticity (H):               0.84   Skew:                            -0.00
Prob(H) (two-sided):                  0.57   Kurtosis:                         3.08
===================================================================================


>>> model_fit.order
(1, 0, 0)

>>> model_fit.seasonal_order
(0, 0, 0, 0)

I hope this is what you are looking for and hopefully it can be of use to you.

It would be interesting to compare this package and what @Federica_F. Proposes, to see which one has a better performance.

$\endgroup$
1
  • $\begingroup$ auto_arima does not fit SARIMAX models (no matter what the output printed above says). They are regressions with SARIMA errors instead. I think the original documentation error is in statsmodels which this library depends on. $\endgroup$
    – Chris Haug
    Commented Jul 11, 2021 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.