-2

Im trying to build a rolling multistep ARIMA forecast. But I cant combine the outputs from the forecast with newer ones.

from pandas import read_csv
from statsmodels.tsa.arima_model import ARIMA

data = read_csv('data_woc.csv', header=0, squeeze=True)
size = 4763
X = data.iloc[:,1:2]
train, test = X[0:size], X[size:len(X)]
history = train
predictions = list()
error = list()
original = list()

for t in range(len(test)):
    model = ARIMA(history, order=(2, 1, 0))
    model_fit = model.fit(disp=0)
    output = model_fit.forecast(steps=7)[0]
    predictions = predictions + output
    obs = test[t:t + 2]
    history = history + obs
print(model_fit.summary())

running it would throw an error

Traceback (most recent call last): File "C:/Users/Usama/Documents/Thesis - Model/ARIMA2_7.py", line 45, in predictions = predictions + output ValueError: operands could not be broadcast together with shapes (0,) (7,)

  • Please reduce and enhance this into the expected [MRE](https://stackoverflow.com/help/minimal-reproducible-example). Show where the intermediate results deviate from the ones you expect. Most urgent is, what are the types and values of the data objects cited in the error message? Since you failed to give us reproductive code, we can't even do that part of your work for you. – Prune Jun 07 '20 at 17:42
  • @Prune i have tried to create MRE, hope it helps now – usama_khurshid Jun 07 '20 at 18:28
  • Much better. However, you haven't completed the MRE. Print out the offending data values. What did you *expect* them to be? – Prune Jun 07 '20 at 18:30
  • @Prune, im sorry but i didnt get you. Im trying to combine the forecasts from this model in an array. So that i can graph all the forecasts combined after the loop finishes. – usama_khurshid Jun 07 '20 at 18:38
  • See this lovely reference for [debugging help](https://ericlippert.com/2014/03/05/how-to-debug-small-programs). IN particular, when the error message tells you that certain values are causing the run-time fault, then we expect you to print those values and explain what you expected instead. – Prune Jun 07 '20 at 20:33

1 Answers1

0

Shapes of Predictions and Output is different. In order to perform any arithmetic operation, use python broadcasting or correct the shapes of both parameters.