Session Ready
Exercise

Extracting a Random Forest parameter

You will now translate the work previously undertaken on the logistic regression model to a random forest model. A parameter of this model is, for a given tree, how it decided to split at each level.

This analysis is not as useful as the coefficients of logistic regression as you will be unlikely to ever explore every split and every tree in a random forest model. However, it is a very useful exercise to peak under the hood at what the model is doing.

In this exercise we will extract a single tree from our random forest model, visualize it and programmatically extract one of the splits.

You have available:

  • A random forest model object, rf_clf
  • An image of the top of the chosen decision tree, tree_viz_image
  • The X_train DataFrame & the original_variables list
Instructions
100 XP
  • Extract the 7th tree (6th index) from the random forest model.
  • Visualize this tree (tree_viz_image) to see the split decisions.
  • Extract the feature & level of the top split.
  • Print out the feature and level together.