load("data/cohort_2007.rda")
initial_split <- rsample::initial_split(cohort_2007, strata = ocup_atual_dic_t2)
train <- rsample::training(initial_split)
test <- rsample::testing(initial_split)
resamples <- rsample::vfold_cv(
train,
v = 3,
repeats = 1,
strata = ocup_atual_dic_t2)
rec <- train |>
recipes::recipe(ocup_atual_dic_t2 ~ .) |>
recipes::update_role(rec, new_role = "id") |>
recipes::step_filter_missing(recipes::all_predictors(), threshold = 0.1) |>
recipes::step_nzv(recipes::all_predictors()) |>
recipes::step_other(recipes::all_nominal_predictors(), threshold = 0.2) |>
recipes::step_dummy(recipes::all_nominal_predictors())
mod <- parsnip::logistic_reg(penalty = tune::tune(), mixture = 1) |>
parsnip::set_mode("classification") |>
parsnip::set_engine("glmnet")
wf <- workflows::workflow() |>
workflows::add_recipe(rec) |>
workflows::add_model(mod)
rs <- tune::tune_grid(
object = wf,
resamples = resamples,
grid = dials::grid_regular(dials::penalty(range = c(-4, -1)),
levels = 20),
metrics = yardstick::metric_set(yardstick::roc_auc,
yardstick::accuracy),
control = tune::control_grid(verbose = TRUE, allow_par = TRUE)
)
rs |> tune::show_best()
work_last_fit <- tune::last_fit(
object = wf,
split = initial_split
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.