https://github.com/nixtla logo
#general
Title
# general
t

Tyler Blume

05/04/2023, 8:15 PM
Hey everyone, quick question about MLForecast: Is there a way to utilize LightGBM's categorical features: https://lightgbm.readthedocs.io/en/latest/Advanced-Topics.html . Specifically for the unique id column? Thanks!
f

fede (nixtla) (they/them)

05/04/2023, 9:04 PM
hey @Tyler Blume! Thanks for using MLForecast. Yes, you can pass your categorial columns as
category
type and the sklearn API of lightgbm (
LGMBRegressor
) will handle them by default. Also if you want to use the
unique_id
as a static variable, you need to create a separate column. And to use it as a categorical feature you need to convert it to
category.
Here’s an example (
unique_id
already is of type
category
):
Copy code
import lightgbm as lgb
from mlforecast import MLForecast
from mlforecast.utils import generate_daily_series


series = generate_daily_series(100, equal_ends=True, n_static_features=2, static_as_categorical=True)

series['my_id_col'] = series['unique_id'].copy()

mlf = MLForecast(
    models=lgb.LGBMRegressor(),
    freq='D',
    lags=[7],
)
mlf.fit(series, static_features=['my_id_col', 'static_0', 'static_1'])

preds = mlf.predict(12)
This is what the series dataframe looks like:
t

Tyler Blume

05/04/2023, 10:56 PM
Hey @fede (nixtla) (they/them) awesome thanks so much. Any plans to make using the id column default behavior? Using a categorical id a long with scaling at the time series level (boxcox, standard, minmax) gives nice performance boosts!
f

fede (nixtla) (they/them)

05/17/2023, 8:44 PM
hey @Tyler Blume! Could you help us open an issue to include that behavior? https://github.com/Nixtla/mlforecast/issues/new/choose Thank you!
t

Tyler Blume

06/22/2023, 7:40 PM
hey @fede (nixtla) (they/them) sorry it took so long to get around to this but I have opened a couple of issues up. I also wrote a wrapper a little while back that does a lot of what I see gives good performance boosts. It only uses LightGBM but it adds some other features that make it a little easier to tune (in my experience) I pushed it to github if interested!
🙌 1
1
f

fede (nixtla) (they/them)

07/04/2023, 9:16 PM
This is really cool, @Tyler Blume! wdyt @José Morales? maybe we could include some of these features natively in mlforecast, would you like to contribute to that @Tyler Blume? 🎉
t

Tyler Blume

07/04/2023, 10:56 PM
Yeah sounds good to me!
@José Morales let me know if you want me to work on adding these. They are also pretty easy code snippets so we could just jump on a call and I could review them and you could add them. Whatever works best for you!
j

José Morales

07/15/2023, 6:07 PM
If you have time to open a PR that'd be great. I think you can create a new module with these features. Let us know if you need help, nbdev takes some time to getting used to
👍 1