Slackbot
11/25/2022, 2:25 PMMax (Nixtla)
11/25/2022, 2:26 PMAndrei Tulbure
11/25/2022, 2:27 PMMax (Nixtla)
11/25/2022, 2:28 PMMax (Nixtla)
11/25/2022, 2:28 PMAndrei Tulbure
11/25/2022, 2:28 PMAndrei Tulbure
11/25/2022, 2:28 PMmodel = lgb.LGBMRegressor
models_ml = model(**params)
ml_fcst = Forecast(
models=models_ml,
freq="W-MON",
lags=[1, 2, 3, 4, 5, 6, 7, 8], )
ml_fcst.fit(
df_train,
id_col="unique_id",
time_col=column_name_for_date,
target_col=column_name_for_qty,)
pred_ml_df = ml_fcst.predict(weeks_to_forecast)
Andrei Tulbure
11/25/2022, 2:29 PMMax (Nixtla)
11/25/2022, 2:29 PMJosé Morales
11/25/2022, 2:38 PMAndrei Tulbure
11/25/2022, 2:40 PMJosé Morales
11/25/2022, 2:42 PMAndrei Tulbure
11/25/2022, 2:43 PMAndrei Tulbure
11/25/2022, 2:43 PMAndrei Tulbure
11/25/2022, 5:20 PMmodel = ETS
models_stats = [model(**params)]
stats_fcst = StatsForecast(
df=df_train, models=models_stats, freq="W-MON", n_jobs=-1
)
stats_fcst.fit(df=df_train)
pred_stats_df = stats_fcst.predict(weeks_to_forecast)
Andrei Tulbure
11/25/2022, 5:20 PMAndrei Tulbure
11/25/2022, 5:21 PMfede (nixtla) (they/them)
11/25/2022, 5:39 PMparams
are you using? The default season_length
is 1.
ETS finds the best model with and without trend. If the data does not exhibit a clear trend, it will opt for the trendless model, so the forecast will be a flat line. Although visually not very attractive, this is the expected behavior as ETS is a weighted average of past observations in its trendless and seasonality-free version.
If you want to explore the seasonality of the weekly data, I recommend setting it using MSTL. For that model you can use season_length=52
. (ETS currently does not allow season lengths greater than 24).
As for LightGBM, we have seen that it is quite good at capturing seasonalities, but be sure to include the relevant features. One way to model the seasonality in the MLForecast
library is by using the differences
argument (https://nixtla.github.io/mlforecast/forecast.html).Andrei Tulbure
11/28/2022, 10:36 AMDarius Marginean
11/28/2022, 10:56 AMDarius Marginean
11/28/2022, 10:56 AMDarius Marginean
11/28/2022, 10:57 AMDarius Marginean
11/28/2022, 10:58 AMDarius Marginean
11/28/2022, 12:29 PMAndrei Tulbure
11/28/2022, 12:31 PMfede (nixtla) (they/them)
11/28/2022, 5:54 PMpip install -U statsforecast
or pip install statsforecast>=1.3.2
. Please let me know if the problem persists after changing the version. 🙌fede (nixtla) (they/them)
11/28/2022, 6:11 PMdifferences
argument, you can make the time series stationary. It is similar to the integrated component of an arima model @Darius Marginean. In the context of mlforecast, it allows considering trend and seasonalityDarius Marginean
11/29/2022, 9:54 AMDarius Marginean
11/29/2022, 11:21 AMDarius Marginean
11/29/2022, 12:33 PMDarius Marginean
11/29/2022, 12:34 PMDarius Marginean
11/29/2022, 2:47 PMdifferences = [1]
and here it is the output:Darius Marginean
11/29/2022, 2:48 PMDarius Marginean
11/29/2022, 2:48 PMmodel = lgb.LGBMRegressor
models_ml = model(**best_hp)
ml_fcst = Forecast(
models=models_ml,
freq="W-MON",
differences = [1],
lags=[i for i in range(1, weeks_to_forecast+1)],
)
ml_fcst.fit(train_df, id_col="unique_id", time_col="ds", target_col="y")
pred_ml_df = ml_fcst.predict(weeks_to_forecast)
Darius Marginean
11/29/2022, 2:50 PMfede (nixtla) (they/them)
12/01/2022, 7:42 PMdifferences
might be a good option. Also, since you’re working with weekly data, you could pass differences=[52]
to capture yearly trends.