Update 2-modeling.R

This commit is contained in:
Kyle Belanger 2023-01-31 09:02:19 -05:00
parent e293f5a4fc
commit cd755881f2

View file

@ -10,6 +10,9 @@ box::use(
,readr ,readr
,gp2 = ggplot2[ggplot, aes] ,gp2 = ggplot2[ggplot, aes]
,rsample ,rsample
,r = recipes
,wf = workflows
,p = parsnip
) )
@ -41,3 +44,22 @@ ds_test <- rsample$testing(model_data_split)
table(ds_train$ft4_dia) %>% prop.table() table(ds_train$ft4_dia) %>% prop.table()
table(ds_test$ft4_dia) %>% prop.table() table(ds_test$ft4_dia) %>% prop.table()
# random forest -----------------------------------------------------------
rf_model <- p$rand_forest(trees = 1900) %>%
p$set_engine("ranger") %>% p$set_mode("classification")
rf_recipe <- r$recipe(ft4_dia ~ . , data = ds_train) %>%
r$update_role(subject_id, new_role = "id") %>%
r$update_role(charttime, new_role = "time") %>%
r$step_impute_knn(r$all_predictors())
rf_workflow <- wf$workflow() %>%
wf$add_model(rf_model) %>%
wf$add_recipe(rf_recipe)
rf_fit <- p$fit(rf_workflow, ds_train)