3

I am trying to make prediction on my ARIMA Model but I stucked in one point

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 ;

# 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 ?

train2 as follows ;

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 ;

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
Ugur Selim Ozen
  • 159
  • 3
  • 10
  • Can you share your train/test data and the predictions? Just print them to the console and show it here. – Arne Decker Feb 08 '22 at 09:11
  • I can't make prediction with predict function. – Ugur Selim Ozen Feb 08 '22 at 09:22
  • Can you please provide `trainData1.index` result? – Shayan Feb 08 '22 at 09:24
  • 1
    `predict` here doesn't work as in, e.g., sklearn. Perhaps you should look at the [documentation](https://www.statsmodels.org/devel/generated/statsmodels.tsa.arima.model.ARIMAResults.predict.html#statsmodels.tsa.arima.model.ARIMAResults.predict). But you probably need [`model_fit.forecast`](https://www.statsmodels.org/devel/generated/statsmodels.tsa.arima.model.ARIMAResults.forecast.html#statsmodels.tsa.arima.model.ARIMAResults.forecast). Also, MA order of 50 is unusual, how/why did you choose it? –  Feb 08 '22 at 10:11

1 Answers1

2

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.

Ugur Selim Ozen
  • 159
  • 3
  • 10