python时间序列股票预测‘20161209’报错的原因

股票预测模型中,创建了ARIMA模型,需要对数据进行预测。

使用predict()方法的时候,
pred = result.predict(‘2014-06-09’,‘2016-12-09’,dynamic=True,typ=‘levels’);
运行结果报错,‘The end argument could not be matched to a location related to the index of the data.’ 结束时间找不到对应的索引。
这就说明可能是我们要预测的数据中不包括这个时间数据。

根据result找到模型的预测时间:
model = ARIMA(stock_train, order=(1, 1, 1),freq=‘W-MON’)
result = model.fit()
打印预测时间的最后一天:stock_train.tail(1)
输出结果:Date
2015-12-28 2.24275
Freq: W-MON, Name: Close, dtype: float64

就是说预测时间里面不包含‘2016-12-09’这个数据。预测只能预测到stock_train数据中的最后一个时间。
尝试把predict()结束时间改成‘2015-12-28’,执行成功。

如果有不对欢迎大家指正,相互学习!

猜你喜欢

转载自blog.csdn.net/Amy_lxq/article/details/89372325
今日推荐