knitr::opts_chunk$set(warning = FALSE, messages = FALSE)
library(tidymodels)

Check performance over a range of values for the penalty parameter

We see that the lasso model performed better with lower amounts of regularization.

targets::tar_read(tuningRidgeResponse) |>
autoplot()

Show the best models for the grid search

tune::show_best(targets::tar_read(tuningRidgeResponse))|>
gt::gt()

Assess varibale importance

best <- select_best(targets::tar_read(tuningRidgeResponse))
lasso_best <- finalize_workflow(
    targets::tar_read(workflowRidgeResponse), best
)

lasso_best |>
fit(targets::tar_read(trainingResponse)) |>
extract_fit_parsnip() |>
vip::vi(lambda = best$penalty) |>
mutate(
    Importance = abs(Importance),
    Variable = forcats::fct_reorder(Variable, Importance)
) |>
ggplot(aes(x = Importance, y = Variable, fill = Sign)) +
    geom_col() +
    scale_x_continuous(expand = c(0, 0)) +
  theme(panel.background = element_blank()) +
    labs(y = NULL)


awconway/eicu_nitro documentation built on Feb. 21, 2022, 4:35 p.m.