Hello All,
I am building decision tree with normal steps:
1. Split the data:
split <- policy %>%
initial_split(prop = 0.80, strata = Lapsed)
train <- training(policy_split)
test <- testing(policy_split)
folds <- vfold_cv(train, strata = Lapsed)
2. Build Decision Tree model
set.seed(123)
tree_spec <- decision_tree() %>%
set_engine("rpart") %>%
set_mode("classification")
tree_wf <- workflow() %>%
add_recipe(pol_rec) %>%
add_model(tree_spec)
set.seed(123)
tree_fit <- fit_resamples(
tree_wf,
resamples = folds,
metrics = metric_set(accuracy,roc_auc,sens, spec),
control = control_resamples(save_pred = TRUE))
3. Final model with last_fit()
fn_metrics <- metric_set(roc_auc, accuracy, sens, spec)
# Decision Tree
tree_final <- last_fit(
tree_wf,
split = split,
metrics = fn_metrics
)
My question is "How I can plot the final Decision Tree for testing data set ?" instead of training data as below code:
tree_final %>%
extract_fit_engine() %>%
rpart.plot::rpart.plot(type = 4, extra = 2,
roundint = FALSE)
Thank you for your help.
Tam Pham