Last answered:

15 Oct 2020

Posted on:

13 Oct 2020

0

ARMA/ARIMA prediction fails

When I am running this below code, this error pops up "Length of passed values is 455, index implies 123." This code is exactly the same code as in the course file. model_ret_ar = ARIMA(df.ret_ftse[1:], order = (5,0,0))
results_ret_ar = model_ret_ar.fit() df_pred_ar = results_ret_ar.predict(start = start_date, end = end_date) df_pred_ar[start_date:end_date].plot(figsize = (20,5), color = "red")
df_test.ret_ftse[start_date:end_date].plot(color = "blue")
plt.title("Predictions vs Actual (Returns)", size = 24)
plt.show()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-69-c08db16ba1ff> in <module>
      2 results_ret_ar = model_ret_ar.fit()
      3 
----> 4 df_pred_ar = results_ret_ar.predict(start = start_date, end = end_date)
      5 
      6 df_pred_ar[start_date:end_date].plot(figsize = (20,5), color = "red")

~\anaconda3\lib\site-packages\statsmodels\base\wrapper.py in wrapper(self, *args, **kwargs)
    113             obj = data.wrap_output(func(results, *args, **kwargs), how[0], how[1:])
    114         elif how:
--> 115             obj = data.wrap_output(func(results, *args, **kwargs), how)
    116         return obj
    117 

~\anaconda3\lib\site-packages\statsmodels\base\data.py in wrap_output(self, obj, how, names)
    443             return self.attach_cov(obj)
    444         elif how == 'dates':
--> 445             return self.attach_dates(obj)
    446         elif how == 'columns_eq':
    447             return self.attach_columns_eq(obj)

~\anaconda3\lib\site-packages\statsmodels\base\data.py in attach_dates(self, result)
    591         # May be zero-dim, for example in the case of forecast one step in tsa
    592         if squeezed.ndim < 2:
--> 593             return Series(squeezed, index=self.predict_dates)
    594         else:
    595             return DataFrame(result, index=self.predict_dates,

~\anaconda3\lib\site-packages\pandas\core\series.py in __init__(self, data, index, dtype, name, copy, fastpath)
    289                 try:
    290                     if len(index) != len(data):
--> 291                         raise ValueError(
    292                             f"Length of passed values is {len(data)}, "
    293                             f"index implies {len(index)}."

ValueError: Length of passed values is 455, index implies 123.
1 answers ( 0 marked as helpful)
Instructor
Posted on:

15 Oct 2020

0
Hey Tushar,    I just replicated your code and I got an output. What start/end dates are you using here? Additionally, what version of Pandas & Statsmodels are you on? Best,  365 Vik  

Submit an answer