【发布时间】:2017-05-01 00:12:14
【问题描述】:
我正在尝试实施时间序列预测,并按照此处找到的有用教程进行操作:https://www.analyticsvidhya.com/blog/2016/02/time-series-forecasting-codes-python/
我的时间序列对象的样本,经过对数转换等可以在下面找到:
ts =
2015-02-01 4.532599
2015-03-01 7.635787
2015-04-01 7.698029
2015-05-01 4.564348
2015-06-01 4.744932
2015-09-01 5.365976
2015-10-01 7.657283
2016-02-01 7.059618
2016-03-01 5.433722
2016-04-01 7.600902
当我开始尝试启动 AR 模型时,即
model = ARIMA(ts_log, order=(1, 1, 0))
results_AR = model.fit(disp=-1)
plt.plot(ts_log)
plt.plot(results_AR.fittedvalues, color='red')
plt.title('RSS: %.4f'% sum((results_AR.fittedvalues-ts_log_diff)**2))
plt.show()
我的问题是当我尝试这样做时,我得到:
TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('<U21') dtype('<U21') dtype('<U21')
当我打印出时间序列索引中的数据类型时,我得到:
DatetimeIndex(['2015-05-01'], dtype='datetime64[ns]', freq=None)
然后我尝试像这样在 ARIMA() 中添加日期参数:
model = ARIMA(dt_ts, order=(1, 1, 0), dates=dt_ts.index.values)
或添加一个单独的数组,其中包含我的所有日期,称为格式化:
model = ARIMA(dt_ts, order=(1, 1, 0), dates=formatted)
在这两种情况下我都得到了这个:
ValueError: Given a pandas object and the index does not contain dates
任何人都知道为什么会发生这种情况以及我该如何解决?
提前致谢。
【问题讨论】:
标签: python time-series forecasting