我正在尝试将AR模型应用于2018年日销售量的销售数据。而在给定范围以下的调用预测功能时会遇到关键错误。
start_index = datetime(2018, 8, 29)
end_index = datetime(2018, 11, 28)
Error details
KeyError: 'only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices'
代码段
start_index = datetime(2018, 8, 29)
end_index = datetime(2018, 11, 28)
AR_predict=AR_output.predict(start=start_index,end=end_index)
AR_predict=AR_predict.cumsum().shift().fillna(0)
AR_predict1=pd.Series(np.ones(test.shape[0]) * np.log(test['Volume'])[0], index = test.index)
AR_predict1=AR_predict1.add(AR_predict,fill_value=0)
AR_predict = np.exp(AR_predict1)
plt.plot(test['Volume'], label = "Test")
plt.plot(AR_predict, color = 'red', label = "Predict")
plt.legend(loc= 'best')
plt.title('RMSE: %.4f'% (np.sqrt(np.dot(AR_predict, test['Volume']))/test.shape[0]))
plt.show()
作为初始尝试,通过的日期范围是测试数据集范围。如果成功,则希望从2018年12月开始每周和每月进行预测。
测试数据集范围
start_index = datetime(2018, 8, 29)
end_index = datetime(2018, 11, 28)