diff --git a/ML/2-modeling.R b/ML/2-modeling.R index 81ae12c..93874f0 100644 --- a/ML/2-modeling.R +++ b/ML/2-modeling.R @@ -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)