Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Model forecast] Exception: No regressors provided #435

Open
iamyihwa opened this issue Mar 7, 2023 · 6 comments
Open

[Model forecast] Exception: No regressors provided #435

iamyihwa opened this issue Mar 7, 2023 · 6 comments

Comments

@iamyihwa
Copy link

iamyihwa commented Mar 7, 2023

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 iamyihwa added the bug label Mar 7, 2023
@iamyihwa
Copy link
Author

iamyihwa commented Mar 7, 2023

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 iamyihwa closed this as completed Mar 7, 2023
@NasreddineD
Copy link

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

@AzulGarza AzulGarza reopened this May 11, 2023
@AzulGarza
Copy link
Member

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?

@NasreddineD
Copy link

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"

@AzulGarza
Copy link
Member

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 AzulGarza removed the bug label Jun 6, 2023
@john-asana
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants