@Feifan-990807 I think this should answer your question
Here's some documentation for the code we're writing, but it says that
tree_depth
is the maximum depth of the tree (i.e. number of splits).
new_dat <- your_recipe %>%
prep() %>%
juice()
fit(final_spec,
y ~ , #fill in your formula here
data = new_dat)
# install.packages("vip") #uncomment and run this ONCE in the console
library(vip)
mtcars_cv <- vfold_cv(mtcars)
linear_reg(mixture = 1, penalty = 3) %>%
set_engine("glmnet") %>%
fit(mpg ~ . , data = mtcars) -> f
f %>%
vi(lambda = lowest_rmse$penalty) %>%
mutate(
Importance = abs(Importance),
Variable = factor(Variable, levels = Variable[order(Importance)])
) %>%
ggplot(aes(x = Importance, y = Variable, fill = Sign)) +
geom_col() +
scale_x_continuous(expand = c(0, 0)) +
labs(y = NULL)