我正在尝试对我的 ARIMA 模型进行预测,但我坚持了一点
from statsmodels.tsa.arima.model import ARIMA
train2 = trainData1["meantemp"][:1170]
test2 = trainData1["meantemp"][1170:]
# p,d,q ARIMA Model
model = ARIMA(train2, order=(1,1,50))
model_fit = model.fit()
print(model_fit.summary())
在这里,trainData1 将日期作为索引(您猜到的是 train2 和 test2)并使用 train2 数据训练了模型,之后我尝试对 test2 数据进行如下预测;
# make predictions
predictions = model_fit.predict(test2)
rmse = mean_squared_error(test2.values, predictions)
rmse
但它给了我以下错误;
TypeError: Cannot convert input [date
2016-03-17 2.375000
2016-03-18 -0.125000
2016-03-19 0.598214
2016-03-20 0.347619
2016-03-21 -0.508333
...
2016-12-28 0.367391
2016-12-29 -1.979296
2016-12-30 -1.142857
2016-12-31 0.957393
2017-01-01 -5.052632
Name: meantemp, Length: 291, dtype: float64] of type <class 'pandas.core.series.Series'> to Timestamp
应该在预测函数内部添加什么作为数据?
train2 如下;
2013-01-02 -2.600000
2013-01-03 -0.233333
2013-01-04 1.500000
2013-01-05 -2.666667
2013-01-06 1.000000
...
2016-03-12 -0.504167
2016-03-13 -0.312500
2016-03-14 -1.875000
2016-03-15 1.691667
2016-03-16 -0.129167
Name: meantemp, Length: 1170, dtype: float64
test2如下;
date
2016-03-17 2.375000
2016-03-18 -0.125000
2016-03-19 0.598214
2016-03-20 0.347619
2016-03-21 -0.508333
...
2016-12-28 0.367391
2016-12-29 -1.979296
2016-12-30 -1.142857
2016-12-31 0.957393
2017-01-01 -5.052632
Name: meantemp, Length: 291, dtype: float64