How can I insert a regularization parameter in tidymodels for boost_tree()? In the normal lightgbm package there is the tuning parameter lambda_l1. I would like to use this in tidymodels as well.
I tried to code it like this, but I am unsure if I am doing right:
lgbm_model <-
boost_tree(
mode = "regression",
# mtry = 1,
trees = tune(),
min_n = tune(),
tree_depth = tune(),
learn_rate = tune(),
loss_reduction = tune()
) %>%
set_engine("lightgbm", lambda = 1)
Since
lambda_l1isn't a main argument forboost_tree(), you would indeed supply that argument toset_engine(). Supply it exactly as it is named inlightgbm::lgb.train()or it'sparamargument, usinglambda_l1. The bonsai package, which implements support for the"lightgbm"engine with parsnip, will take care of passing that argument to the right place.Your code would look something like this:
To confirm that
lambda_l1was supplied as you intended, you can extract the underlying LightGBM fit and poke inside of it:Created on 2024-03-28 with reprex v2.1.0
:)