J.P*_*.P. 6 python time-series statsmodels arima
我最近正在阅读 Susan Li 撰写的关于 Python 时间序列分析的教程。我正在以下系列上拟合时间序列 SARIMAX 模型:
y['2017':]
OUT:
Order Date
2017-01-01 397.602133
2017-02-01 528.179800
2017-03-01 544.672240
2017-04-01 453.297905
2017-05-01 678.302328
2017-06-01 826.460291
2017-07-01 562.524857
2017-08-01 857.881889
2017-09-01 1209.508583
2017-10-01 875.362728
2017-11-01 1277.817759
2017-12-01 1256.298672
Freq: MS, Name: Sales, dtype: float64
Run Code Online (Sandbox Code Playgroud)
使用以下内容:
mod = sm.tsa.statespace.SARIMAX(y,
order=(1, 1, 1),
seasonal_order=(1, 1, 0, 12),
enforce_stationarity=False,
enforce_invertibility=False)
results = mod.fit()
print(results.summary().tables[1])
Run Code Online (Sandbox Code Playgroud)
现在,直到这里为止效果都很好,但是当我尝试可视化结果时,我收到以下错误:
results.plot_diagnostics(figsize=(16, 8))
Run Code Online (Sandbox Code Playgroud)
OUT:
ValueError Traceback (most recent call last)
<ipython-input-16-6cfeaa52b7c1> in <module>
----> 1 results.plot_diagnostics(figsize=(16, 8))
2 plt.show()
~/opt/anaconda3/lib/python3.8/site-packages/statsmodels/tsa/statespace/mlemodel.py in plot_diagnostics(self, variable, lags, fig, figsize, truncate_endog_names)
4282
4283 if resid.shape[0] < max(d, lags):
-> 4284 raise ValueError(
4285 "Length of endogenous variable must be larger the the number "
4286 "of lags used in the model and the number of observations "
ValueError: Length of endogenous variable must be larger the the number of lags used in the model and the number of observations burned in the log-likelihood calculation.
<Figure size 1152x576 with 0 Axes>
Run Code Online (Sandbox Code Playgroud)
有谁知道如何解决这个问题,如果它是某种库错误,并且如果无法直接修复,那么我怎样才能获得所有诊断图?
小智 5
对于新人来说,山塔努的意思是 - 而不是这个 -
mod = sm.tsa.statespace.SARIMAX(y,
enter code hereorder=(1, 1, 1),
seasonal_order=(1, 1, 0, 12),
enforce_stationarity=False,
enforce_invertibility=False)
Run Code Online (Sandbox Code Playgroud)
你可以写-enforce_stationarity=False, -这被删除,你也可以评论它-#enforce_stationarity=False,
mod = sm.tsa.statespace.SARIMAX(y, order=(1, 1, 1),
seasonal_order=(1, 1, 0, 12),
enforce_invertibility=False)
Run Code Online (Sandbox Code Playgroud)
小智 -1
要解决 ARIMA 模型中的此错误,出于某种原因,更改图形大小将解决您的问题。就像我在下面所做的那样:
结果.plot_diagnostics(figsize=(15, 12)) plt.show()
归档时间: |
|
查看次数: |
6975 次 |
最近记录: |