Update 2-modeling.R
This commit is contained in:
parent
cd755881f2
commit
3fb002a12f
1 changed files with 13 additions and 1 deletions
|
@ -13,6 +13,7 @@ box::use(
|
|||
,r = recipes
|
||||
,wf = workflows
|
||||
,p = parsnip
|
||||
,ys = yardstick
|
||||
)
|
||||
|
||||
|
||||
|
@ -48,13 +49,14 @@ 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())
|
||||
r$step_impute_bag(r$all_numeric())
|
||||
|
||||
|
||||
|
||||
|
@ -63,3 +65,13 @@ rf_workflow <- wf$workflow() %>%
|
|||
wf$add_recipe(rf_recipe)
|
||||
|
||||
rf_fit <- p$fit(rf_workflow, ds_train)
|
||||
|
||||
rf_predict <- ds_train %>%
|
||||
dplyr::select(ft4_dia) %>%
|
||||
dplyr::bind_cols(
|
||||
predict(rf_fit, ds_train)
|
||||
,predict(rf_fit, ds_train, type = "prob")
|
||||
)
|
||||
|
||||
ys$accuracy(rf_predict, ft4_dia, .pred_class)
|
||||
ys$conf_mat(rf_predict, ft4_dia, .pred_class)
|
||||
|
|
Loading…
Reference in a new issue