CommencerCommencer gratuitement

Create full random forest model

Random forest models naturally perform feature selection as they build many subtrees from random subsets of the features. One way to understand feature importances is to build a model and then extract the feature importances. So, in this exercise, you will use the Healthcare Job Attrition data to train a rand_forest() classification model from which you can extract feature importances. To make feature importances available, be sure to create the model with importance = "impurity". The train and test sets are available to you.

The tidyverse, tidymodels, and vip packages have been loaded for you.

Cet exercice fait partie du cours

Dimensionality Reduction in R

Afficher le cours

Instructions

  • Define a random forest classification model with 200 trees that you can use to extract feature importances.
  • Fit the random forest model with all predictors.
  • Bind the predictions to the test set.
  • Calculate the F1 metric.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Specify the random forest model
rf_spec <- ___(mode = "___", ___ = ___) %>% 
  set_engine("___", ___ = "___") 

# Fit the random forest model with all predictors
rf_fit <- ___ %>% 
  ___(___, data = ___)

# Create the test set prediction data frame
predict_df <- ___ %>% 
  bind_cols(predict = ___(___, ___))

# Calculate F1 performance
f_meas(predict_df, ___, .pred_class)
Modifier et exécuter le code