Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Dimensionality Reduction in R

Cursus bekijken

Oefeninstructies

  • 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.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# 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)
Code bewerken en uitvoeren