我试图预测股票价格,我得到了这个错误。
import statsmodels.api as smapi
model = smapi.tsa.arima.ARIMA(train_data, order = (1,1,0))
fitted = model.fit()
print(test_data.shape)
fc,se,conf=fitted.forecast(638, alpha = 0.05)
fc_series = pd.Series(fc, index = test_data.index)
lower_series = pd.Series(conf[:, 0], index = test_data.index)
upper_series = pd.Series(conf[:, 1], index = test_data.index)
字符串
对于此行fc,se,conf=fitted.forecast(638, alpha = 0.05)
我得到的错误是
ValueError: too many values to unpack (expected 3)
型
我不确定是什么导致了错误。我输入了638,因为这是test_data
的形状
我真的很感激在这方面的帮助!
- 编辑 *
train_data.head()
是这样的,形状为1888
x1c 0d1x的数据test_data.head()
是这样的,形状为638
的
希望这能帮上忙。我仍然不确定为什么这不起作用。
1条答案
按热度按时间lf3rwulv1#
在您提供的
forecast()
代码行中,您为(fc, se, and conf)
请求的变量与forecast()
函数实际返回的变量之间似乎不匹配。statsmodels.tsa.arima.model.ARIMAResults
模块中的forecast()
函数仅返回指定时间段的预测值,而不返回se
和conf
变量。我想你是混淆了
ARMA
模型和ARIMA
模型。在ARMA
模型中,forecast()
方法返回这3个值。要解决此处的问题,您可以修改代码以仅请求预测值。下面是更新后的代码:
字符串
通过进行此更改,您将收到指定时间段(在给定示例中为638天)的未来值(fc)的
Series
。您可以参考
ARIMA
文档here。您可以参考
ARMA
文档here这里有一个工作示例:
型