Is it possible to plot trees in random forest model ? The following is the sample dataset which can be used for explaining. Im sorry, i didnt find any such example online and hence didnt try anything by my own.The following is just a sample workaround.
library(palmerpenguins)
penguins <- penguins %>%
filter(!is.na(sex)) %>%
select(-year, -island)
Splitting the data
set.seed(123)
penguin_split <- initial_split(penguins, strata = sex)
penguin_train <- training(penguin_split)
penguin_test <- testing(penguin_split)
creating the model specifications.
rf_spec <- rand_forest() %>%
set_mode("classification") %>%
set_engine("ranger")
penguin_wf <- workflow() %>%
add_formula(sex ~ .)
Applying to the test data
penguin_final <- penguin_wf %>%
add_model(rf_spec) %>%
last_fit(penguin_split)
Now how to plot the trees ?
Thanks in advance.