问题描述
我正在尝试仅使用自动回归算法来构建旧式学校模型.我发现在 statsmodel
包中有一个实现.我已经阅读了文档,据我所知它应该可以作为ARIMA使用.所以,这是我的代码:
I'm trying to build old school model using only auto regression algorithm. I found out that there's an implementation of it in statsmodel
package. I've read the documentation, and as I understand it should work as ARIMA. So, here's my code:
import statsmodels.api as sm
model = sm.tsa.AutoReg(df_train.beer, 12).fit()
当我想预测新值时,我正在尝试遵循文档:
And when I want to predict new values, I'm trying to follow the documentation:
y_pred = model.predict(start=df_test.index.min(), end=df_test.index.max())
# or
y_pred = model.predict(start=100, end=1000)
两者均返回NaN列表.
Both returns a list of NaNs.
此外,当我键入 model.predict(0,df_train.size-1)
时,它会预测实际值,但是 model.predict(0,df_train.size)
预测NaNs列表.
Also, when I type model.predict(0, df_train.size - 1)
it predicts real values, but model.predict(0, df_train.size)
predicts NaNs list.
我做错什么了吗?
PS .我知道有ARIMA,ARMA或SARIMAX算法,可以用作基本的自动回归.但是我需要确切的AutoReg.
P.S. I know there's ARIMA, ARMA or SARIMAX algorithms, that can be used as basic auto regression. But I need exactly AutoReg.
推荐答案
您可以使用此代码进行预测
You can use this code for forecasting
model = sm.tsa.AutoReg(df_train.beer, 12).fit()
y_pred = model.model.predict(model.params, start=df_test.index.min(), end=df_test.index.max())
这篇关于如何使用AutoReg预测时间序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!