Random Forests with tidymodels

Learn how to train a random forest ensemble using tidymodels.

We'll cover the following...

Training a random forest

One advantage of the workflow approach of tidymodels is the ability to change the machine learning algorithm quickly. The following code compares using a CART classification tree vs. a random classification forest.

Press + to interact
#================================================================================================
# Specify a CART classification tree
#
titanic_model <- decision_tree() %>%
set_engine("rpart") %>%
set_mode("classification")
#================================================================================================
# Specify a random classification forest
#
titanic_model <- rand_forest(trees = 500) %>%
set_engine("randomForest") %>%
set_mode("classification")

The code above uses the rand_forest() function from the parsnip package to specify using the random forest algorithm with default hyperparameter values. The code further specifies using the randomForest package’s algorithm to train a random ...