[英]Time Series Prediction with statsmodels.tsa.arima.model import ARIMA
I am trying to make prediction on my ARIMA Model but I stucked in one point我正在尝试对我的 ARIMA Model 进行预测,但我停留在一点
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())
Here, trainData1 has date as index (both train2 and test2 as you guess) and trained model with train2 data, after that I tried to make prediction on test2 data as follows;在这里,trainData1 以日期作为索引(如您猜测的那样包括 train2 和 test2)并使用 train2 数据训练 model,之后我尝试对 test2 数据进行如下预测;
# make predictions
predictions = model_fit.predict(test2)
rmse = mean_squared_error(test2.values, predictions)
rmse
But it gives me the following error;但它给了我以下错误;
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
What should be added to inside of predict function as data?预测 function 的内部应该添加什么作为数据?
train2 as follows;训练2如下;
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 as follows;测试2如下;
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
I solved my own problem as follows;我按如下方式解决了自己的问题;
# make predictions
predictions = model_fit.forecast(291)
print(f'ARIMA Model Test Data MSE: {np.mean((predictions.values - test2.values)**2):.3f}')
with forecast function, model predicted next 291 step which is day here as it is daily time-series and made evaluation with MSE metric using predictions and actual test values.预测 function,model 预测接下来的 291 步,这里是一天,因为它是每日时间序列,并使用预测和实际测试值使用 MSE 指标进行评估。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.