如何在python中使用AutoReg预测时间序列

如何在python中使用AutoReg预测时间序列

本文介绍了如何在python中使用AutoReg预测时间序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试仅使用自动回归算法来构建老式模型.我发现在 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)预测 NaN 列表.

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.

我做错了吗?

P.S. 我知道有 ARIMA、ARMA 或 SARIMAX 算法,可以用作基本的自动回归.但我需要完全自动注册.

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())

这篇关于如何在python中使用AutoReg预测时间序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 12:29