ARIMA need exogenous array
When I tried to follow the video and ran the following code, I have the corresponding error message and don't know how to fix it.
model_auto = auto_arima(df.ret_ftse[1:], exogenous = df[["ret_spx","ret_dax","ret_nikkei"]][1:],
m = 5, max_p = 5, max_q = 5, max_P=5, max_Q=5) df_auto_pred = pd.DataFrame(model_auto.predict(n_periods = len(df_test[start_date:end_date])),
exogenous = df_test[["ret_spx","ret_dax","ret_nikkei"]][start_date:end_date],
index = df_test[start_date:end_date].index)
df_auto_pred.plot(figsize =(20,5), color = "red")
df_test.ret_ftse[start_date:end_date].plot(color = "blue")
plt.title("Auto Model Predictions vs Real Data", size = 24)
plt.show()
m = 5, max_p = 5, max_q = 5, max_P=5, max_Q=5) df_auto_pred = pd.DataFrame(model_auto.predict(n_periods = len(df_test[start_date:end_date])),
exogenous = df_test[["ret_spx","ret_dax","ret_nikkei"]][start_date:end_date],
index = df_test[start_date:end_date].index)
df_auto_pred.plot(figsize =(20,5), color = "red")
df_test.ret_ftse[start_date:end_date].plot(color = "blue")
plt.title("Auto Model Predictions vs Real Data", size = 24)
plt.show()
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-28-3266f5b3ac5e> in <module> 3 m = 5, max_p = 5, max_q = 5, max_P=5, max_Q=5) 4 ----> 5 df_auto_pred = pd.DataFrame(model_auto.predict(n_periods = len(df_test[start_date:end_date])), 6 exogenous = df_test[["ret_spx","ret_dax","ret_nikkei"]][start_date:end_date], 7 index = df_test[start_date:end_date].index) ~\anaconda3\lib\site-packages\pmdarima\arima\arima.py in predict(self, n_periods, exogenous, return_conf_int, alpha) 626 627 # if we fit with exog, make sure one was passed: --> 628 exogenous = self._check_exog(exogenous) # type: np.ndarray 629 if exogenous is not None and exogenous.shape[0] != n_periods: 630 raise ValueError('Exogenous array dims (n_rows) != n_periods') ~\anaconda3\lib\site-packages\pmdarima\arima\arima.py in _check_exog(self, exogenous) 493 if self.fit_with_exog_: 494 if exogenous is None: --> 495 raise ValueError('When an ARIMA is fit with an exogenous ' 496 'array, it must also be provided one for ' 497 'predicting or updating observations.') ValueError: When an ARIMA is fit with an exogenous array, it must also be provided one for predicting or updating observations.
1 answers ( 0 marked as helpful)
Hey Liqian,
The exogenous part needs to be within the predict method when creating the new data frame. Hence, just move the closing parenthesis after exogenous = df_test[[“ret_spx”,”ret_dax”,”ret_nikkei”]][start_date:end_date] like so:
df_auto_pred = pd.DataFrame(model_auto.predict(n_periods = len(df_test[start_date:end_date]),instead of
exogenous = df_test[[“ret_spx”,”ret_dax”,”ret_nikkei”]][start_date:end_date]),
index = df_test[start_date:end_date].index)
df_auto_pred = pd.DataFrame(model_auto.predict(n_periods = len(df_test[start_date:end_date])),Best, 365 Vik
exogenous = df_test[[“ret_spx”,”ret_dax”,”ret_nikkei”]][start_date:end_date],
index = df_test[start_date:end_date].index)