Path: blob/master/Time Forecasting using Python/SARIMAX.ipynb
3074 views
Kernel: Python 3 (ipykernel)
In [1]:
In [2]:
Out[2]:
Check for Stationarity: Use the ADF test (Augmented Dickey-Fuller) to check whether the time series is stationary. A non-stationary series might need differencing.
In [3]:
Out[3]:
ADF Statistic: -1.1320384625097908
p-value: 0.702127738589838
In [4]:
Fit the SARIMAX Model
In [5]:
Out[5]:
C:\Users\suyashi144893\Anaconda3\lib\site-packages\statsmodels\tsa\statespace\sarimax.py:966: UserWarning: Non-stationary starting autoregressive parameters found. Using zeros as starting parameters.
warn('Non-stationary starting autoregressive parameters'
C:\Users\suyashi144893\Anaconda3\lib\site-packages\statsmodels\tsa\statespace\sarimax.py:978: UserWarning: Non-invertible starting MA parameters found. Using zeros as starting parameters.
warn('Non-invertible starting MA parameters found.'
SARIMAX Results
==========================================================================================
Dep. Variable: value No. Observations: 100
Model: SARIMAX(1, 1, 1)x(1, 1, 1, 12) Log Likelihood -132.907
Date: Fri, 13 Sep 2024 AIC 275.813
Time: 14:05:23 BIC 288.143
Sample: 01-31-2010 HQIC 280.778
- 04-30-2018
Covariance Type: opg
==============================================================================
coef std err z P>|z| [0.025 0.975]
------------------------------------------------------------------------------
ar.L1 0.9830 0.128 7.659 0.000 0.731 1.234
ma.L1 -0.9136 0.109 -8.356 0.000 -1.128 -0.699
ar.S.L12 0.1951 0.212 0.919 0.358 -0.221 0.611
ma.S.L12 -0.9994 94.174 -0.011 0.992 -185.577 183.578
sigma2 0.9863 92.705 0.011 0.992 -180.712 182.684
===================================================================================
Ljung-Box (L1) (Q): 0.12 Jarque-Bera (JB): 0.39
Prob(Q): 0.73 Prob(JB): 0.82
Heteroskedasticity (H): 0.67 Skew: -0.15
Prob(H) (two-sided): 0.29 Kurtosis: 2.85
===================================================================================
Warnings:
[1] Covariance matrix calculated using the outer product of gradients (complex-step).
In [6]:
Out[6]:
In [15]:
Out[15]:
C:\Users\suyashi144893\Anaconda3\lib\site-packages\statsmodels\tsa\statespace\sarimax.py:966: UserWarning: Non-stationary starting autoregressive parameters found. Using zeros as starting parameters.
warn('Non-stationary starting autoregressive parameters'
C:\Users\suyashi144893\Anaconda3\lib\site-packages\statsmodels\tsa\statespace\sarimax.py:978: UserWarning: Non-invertible starting MA parameters found. Using zeros as starting parameters.
warn('Non-invertible starting MA parameters found.'
C:\Users\suyashi144893\Anaconda3\lib\site-packages\statsmodels\base\model.py:607: ConvergenceWarning: Maximum Likelihood optimization failed to converge. Check mle_retvals
warnings.warn("Maximum Likelihood optimization failed to "
SARIMAX Results
==========================================================================================
Dep. Variable: value No. Observations: 100
Model: SARIMAX(1, 1, 1)x(1, 1, 1, 12) Log Likelihood -133.591
Date: Fri, 13 Sep 2024 AIC 279.181
Time: 14:17:50 BIC 293.977
Sample: 01-31-2010 HQIC 285.139
- 04-30-2018
Covariance Type: opg
==============================================================================
coef std err z P>|z| [0.025 0.975]
------------------------------------------------------------------------------
ad_spend -0.0010 0.001 -1.263 0.207 -0.002 0.001
ar.L1 0.0813 2.044 0.040 0.968 -3.925 4.087
ma.L1 -0.0302 2.077 -0.015 0.988 -4.100 4.040
ar.S.L12 0.2219 0.238 0.932 0.351 -0.245 0.688
ma.S.L12 -0.9072 0.512 -1.771 0.076 -1.911 0.097
sigma2 1.0639 0.416 2.559 0.011 0.249 1.879
===================================================================================
Ljung-Box (L1) (Q): 0.11 Jarque-Bera (JB): 0.43
Prob(Q): 0.74 Prob(JB): 0.81
Heteroskedasticity (H): 0.67 Skew: -0.15
Prob(H) (two-sided): 0.29 Kurtosis: 2.83
===================================================================================
Warnings:
[1] Covariance matrix calculated using the outer product of gradients (complex-step).
In [13]:
In [14]:
Out[14]:
2018-05-31 105.634258
2018-06-30 105.675322
2018-07-31 105.334010
2018-08-31 106.021028
2018-09-30 105.547179
2018-10-31 106.115345
2018-11-30 106.023134
2018-12-31 106.365191
2019-01-31 106.710122
2019-02-28 107.365463
2019-03-31 107.671045
2019-04-30 107.865050
Freq: M, Name: predicted_mean, dtype: float64
In [ ]: