0

I'm trying to learn how to forecast data based on the ARIMA model that is in the library Statsmodel, but I keep running into issues. Currently i'm just trying to line up my prediction next to the actual to test my model but i cant get the ARIMA model results to cooperate

import statsmodels.api as sm

model = sm.tsa.arima.ARIMA(train, order=(4,1,2))
result = model.fit()

result.summary()

step = 10

fc, se, conf = result.forecast(step)

This all works but the last step is throwing this error

 ValueError                                Traceback (most recent call last)
Input In [57], in <module>
      1 step = 10
----> 3 fc, se, conf = result.forecast(step)

ValueError: too many values to unpack (expected 3)

I've been reading the documentation for hours but I cant get anywhere with it. Any help would be greatly appreciated

  • 1
    Hi, did you look at `help(result.forecast)`? It says it returns the mean of the predicted values (and only those). So it returns 1 thing but you expect 3 things, hence the error. I guess `fc` means "forecasts", right? Then `fc = result.forecast(step)` directly. `conf` is confidence intervals? Then you get that by `conf = result.get_forecast(step).conf_int()` (I agree that API is somewhat unintuitive). Not sure what `se` means. (standard error on parameter estimates? then `se = result.bse`; you can see [here](https://stackoverflow.com/questions/31523921).) –  Jan 12 '22 at 21:19

1 Answers1

0

First of all, you try to save what a function is returning, in this case you expect three values. One for fc, one for se and one for conf. The problem is that the function .forecast() returns the prediction as a single object. You try to unpack a single object, but Python expects three. Therefore, “too many values to unpack…”. You can read the documentation of the function here to check what it returns:

https://www.statsmodels.org/dev/generated/statsmodels.tsa.arima.model.ARIMAResults.forecast.html#statsmodels.tsa.arima.model.ARIMAResults.forecast

enter image description here

https://www.statsmodels.org/dev/generated/statsmodels.tsa.arima.model.ARIMAResults.html

If you try this it will save all predictions in the object “preds” as a pandas Series:

preds = result.forecast(step)

Secondly, if you want to know what a function is returning, you can simply write only the function (without … = function()) as the last line of a cell, then you can see what the function returns. Or you can check the documentation. You can print the object’s type with print(type(result)), it will return “statsmodels.tsa.arima.model.ARIMAResultsWrapper” and if you google you get to the documentation above.

Arne Decker
  • 808
  • 1
  • 3
  • 9