Nixtla / mlforecast

Scalable machine 🤖 learning for time series forecasting.
https://nixtlaverse.nixtla.io/mlforecast
Apache License 2.0
860 stars 84 forks source link

[AutoMLForecast] Can't use AutoMLForecast with dynamic features #422

Closed KuriaMaingi closed 2 hours ago

KuriaMaingi commented 1 day ago

What happened + What you expected to happen

Attempting to run an AutoMLForecast with dynamic variables as below generates this error:

`lgb_fcst_auto = AutoMLForecast( models= {"lgb": AutoLightGBM(), "ridge":AutoRidge()}, freq=pd.DateOffset(weeks=4), # Frequency is every 4 weeks season_length=12, ) lgb_fcst_auto.fit(df, n_windows=2, h=3, num_samples=2)

ValueError: col_x is declared as a static feature but its values change over time. Please set the static_features argument to indicate which features are static. If all of your features are dynamic please set static_features=[]. `

However, setting static_features = [] as below generates a different error:

`lgb_fcst_auto = AutoMLForecast( models= {"lgb": AutoLightGBM(), "ridge":AutoRidge()}, freq=pd.DateOffset(weeks=4), # Frequency is every 4 weeks season_length=12, ) lgb_fcst_auto.fit(df, n_windows=2, h=3, num_samples=2, static_features=[])

TypeError: AutoMLForecast.fit() got an unexpected keyword argument 'static_features' `

My question: Is there a way to pass kwargs to the underlying fit function? Are dynamic features not possible with AutoMLForecast?

I checked the documentation & the example shown didn't appear to be using dynamic features.

Versions / Dependencies

mlforecast 0.13.4

Reproduction script

`from mlforecast.utils import generate_daily_series, generate_prices_for_series from mlforecast.auto import (AutoLightGBM, AutoMLForecast, AutoRidge)

series = generate_daily_series( 100, equal_ends=True, n_static_features=2 ).rename(columns={'static_1': 'product_id'}) prices_catalog = generate_prices_for_series(series) series_with_prices = series.merge(prices_catalog, how='left')

lgb_fcst_auto = AutoMLForecast( models= {"lgb": AutoLightGBM(), "ridge":AutoRidge()}, freq='D', season_length=7, ) lgb_fcst_auto.fit(series_with_prices, n_windows=2, h=3, num_samples=2, static_features=[])`

Issue Severity

High: It blocks me from completing my task.

jmoralez commented 14 hours ago

Hey. You have to provide that through the fit_config argument in the constructor, e.g.

AutoMLForecast(..., fit_config=lambda trial: {'static_features': []})
KuriaMaingi commented 2 hours ago

Yes that resolved it. Thanks