statsforecast icon indicating copy to clipboard operation
statsforecast copied to clipboard

[Model forecast] Exception: No regressors provided

Open iamyihwa opened this issue 1 year ago • 6 comments

What happened + What you expected to happen

  1. Exception : No regressors provided
  2. output dataframe with predictions from each model

RemoteTraceback Traceback (most recent call last) RemoteTraceback: """ Traceback (most recent call last): File "/anaconda/envs/jupyter_env/lib/python3.8/multiprocessing/pool.py", line 125, in worker result = (True, func(*args, **kwds)) File "/anaconda/envs/jupyter_env/lib/python3.8/site-packages/statsforecast/core.py", line 199, in forecast raise error File "/anaconda/envs/jupyter_env/lib/python3.8/site-packages/statsforecast/core.py", line 185, in forecast res_i = model.forecast( File "/anaconda/envs/jupyter_env/lib/python3.8/site-packages/statsforecast/models.py", line 345, in forecast fcst = forecast_arima(mod, h, xreg=X_future, level=level) File "/anaconda/envs/jupyter_env/lib/python3.8/site-packages/statsforecast/arima.py", line 1485, in forecast_arima raise Exception("No regressors provided") Exception: No regressors provided """

The above exception was the direct cause of the following exception:

Exception Traceback (most recent call last) Cell In[92], line 1 ----> 1 forecasts_df = sf.forecast(h=14 , level=[90]) 3 forecasts_df.head()

File /anaconda/envs/jupyter_env/lib/python3.8/site-packages/statsforecast/core.py:680, in _StatsForecast.forecast(self, h, df, X_df, level, fitted, sort_df) 670 res_fcsts = self.ga.forecast( 671 models=self.models, 672 h=h, (...) 677 verbose=self.verbose, 678 ) 679 else: --> 680 res_fcsts = self.forecast_parallel(h=h, fitted=fitted, X=X, level=level) 681 if fitted: 682 self.fcst_fitted_values = res_fcsts["fitted"]

File /anaconda/envs/jupyter_env/lib/python3.8/site-packages/statsforecast/core.py:939, in _StatsForecast._forecast_parallel(self, h, fitted, X, level) 927 future = executor.apply_async( 928 ga.forecast, 929 ( (...) 936 ), 937 ) 938 futures.append(future) --> 939 out = [f.get() for f in futures] 940 fcsts = [d["forecasts"] for d in out] 941 fcsts = np.vstack(fcsts)

File /anaconda/envs/jupyter_env/lib/python3.8/site-packages/statsforecast/core.py:939, in (.0) 927 future = executor.apply_async( 928 ga.forecast, 929 ( (...) 936 ), 937 ) 938 futures.append(future) --> 939 out = [f.get() for f in futures] 940 fcsts = [d["forecasts"] for d in out] 941 fcsts = np.vstack(fcsts)

File /anaconda/envs/jupyter_env/lib/python3.8/multiprocessing/pool.py:771, in ApplyResult.get(self, timeout) 769 return self._value 770 else: --> 771 raise self._value

File /anaconda/envs/jupyter_env/lib/python3.8/multiprocessing/pool.py:125, in worker() 123 job, i, func, args, kwds = task 124 try: --> 125 result = (True, func(*args, **kwds)) 126 except Exception as e: 127 if wrap_exception and func is not _helper_reraises_exception:

File /anaconda/envs/jupyter_env/lib/python3.8/site-packages/statsforecast/core.py:199, in forecast() 190 res_i = fallback_model.forecast( 191 h=h, 192 y=y_train, (...) 196 **kwargs, 197 ) 198 else: --> 199 raise error 200 cols_m = [ 201 key 202 for key in res_i.keys() 203 if any(key.startswith(m) for m in matches) 204 ] 205 fcsts_i = np.vstack([res_i[key] for key in cols_m]).T

File /anaconda/envs/jupyter_env/lib/python3.8/site-packages/statsforecast/core.py:185, in forecast() 183 kwargs["level"] = level 184 try: --> 185 res_i = model.forecast( 186 h=h, y=y_train, X=X_train, X_future=X_f, fitted=fitted, **kwargs 187 ) 188 except Exception as error: 189 if fallback_model is not None:

File /anaconda/envs/jupyter_env/lib/python3.8/site-packages/statsforecast/models.py:345, in forecast() 307 with np.errstate(invalid="ignore"): 308 mod = auto_arima_f( 309 x=y, 310 d=self.d, (...) 343 period=self.season_length, 344 ) --> 345 fcst = forecast_arima(mod, h, xreg=X_future, level=level) 346 res = {"mean": fcst["mean"]} 347 if fitted:

File /anaconda/envs/jupyter_env/lib/python3.8/site-packages/statsforecast/arima.py:1485, in forecast_arima() 1483 elif usexreg: 1484 if xreg is None: -> 1485 raise Exception("No regressors provided") 1486 # ncxreg = len([ncoef for ncoef in model['coef'].keys() if 'ex_' in ncoef]) 1487 # if xreg.shape[1] != ncxreg: 1488 # raise Exception('Number of regressors does not match fitted model"') 1489 pred, se = predict_arima(model, n_ahead=h, newxreg=xreg)

Exception: No regressors provided

Versions / Dependencies

1.4.0 AzureML Environment

Reproduction script

from statsforecast import StatsForecast from statsforecast.models import AutoARIMA, AutoETS, Naive

season_length = 52 # Weekly data 12 # Monthly data horizon = 14 # Predict the lenght of the test df

Include the models you imported

models = [ AutoARIMA(season_length=season_length), AutoETS(season_length=season_length), Naive() ]

image from statsforecast import StatsForecast from statsforecast.models import AutoARIMA, AutoETS, Naive

season_length = 52 # Weekly data 12 # Monthly data horizon = 14 # Predict the lenght of the test df

Include the models you imported

models = [ AutoARIMA(season_length=season_length), AutoETS(season_length=season_length), Naive() ]

Instansiate the StatsForecast class as sf

sf = StatsForecast( df=y_train_short, models=models, freq='W', n_jobs=-1 )

forecasts_df = sf.forecast(h=14 , level=[90])

forecasts_df.head()

Issue Severity

High: It blocks me from completing my task.

iamyihwa avatar Mar 07 '23 14:03 iamyihwa

It seems the error was caused by the extra column that was present (other than ds, and y), after removing the extra column, the error doesn't appear anymore. Therefore closing the issue.

iamyihwa avatar Mar 07 '23 14:03 iamyihwa

Hi, I actually have the same issue when adding exogenous data. But no error with the exact same code without exogenous data. So the issue could be reopen please?

Thank you

NasreddineD avatar May 11 '23 19:05 NasreddineD

Hey @NasreddineD! Thank you for using statsforecast and letting us know about the issue. Could you share a reproducible example to dig into the problem?

AzulGarza avatar May 11 '23 20:05 AzulGarza

Hi @FedericoGarza, please find below the code:

sf = StatsForecast( models = models, freq='MS', n_jobs=-1, verbose= True )

crossvalidation_df = sf.cross_validation( df=df_ts, # df_ts containing Exogenous data h=24, step_size=1, n_windows=100 )

sf.forecast(h=12)

Exception: No regressors provided

Please note: There is no error with only "ds", "y" and "unique_id"

NasreddineD avatar May 12 '23 09:05 NasreddineD

hey @NasreddineD! Thank you.

If you include exogenous variables in your data, once you call forecast you have to add the exogenous variables of the future in the X_df argument. For example, if your dataframe df_ts contains the columns ['unique_id', 'ds', 'y', 'holiday'], the models will be trained using the exogenous variable holiday, but for the model to create forecast, it needs the future values of holiday. Those future values should be added through the X_df argument and contain the columns ['unique_id', 'ds', 'holiday']. Please ensure you pass the same number of values as your forecasting horizon. Here's a tutorial on the topic.

Please let us know if something else needs to be clarified. :)

AzulGarza avatar May 15 '23 23:05 AzulGarza

For posterity, this is the fixed link which is broken in FG's post above https://nixtla.github.io/statsforecast/docs/how-to-guides/exogenous.html

john-asana avatar Aug 21 '23 22:08 john-asana