8.59 Random Forest using a set of features (mtry)

By default, randomForest() p / 3 variables when building a random forest of regression trees, and sqrt(p) variables when building a random forest of classification trees. Here we use mtry = 6, trees = 2000 and min_n = 10.

rf_spec <- rand_forest(mtry = 6, trees = 2000, min_n = 10) %>%
     set_engine("randomForest", importance = TRUE) %>%
     set_mode("regression")

Fit the model

rf_fit <- fit(rf_spec, Sales ~ ., data = carseats_train)