5. Decision Trees and Random Forests
Activity 5.01: Cross-Validation Grid Search with Random Forest
Solution:
- Create a dictionary representing the grid for the
max_depth
andn_estimators
hyperparameters that will be searched. Include depths of 3, 6, 9, and 12, and 10, 50, 100, and 200 trees. Leave the other hyperparameters at their defaults. Create the dictionary using this code:rf_params = {'max_depth':[3, 6, 9, 12], Â Â Â Â Â Â Â Â Â Â Â Â Â 'n_estimators':[10, 50, 100, 200]}
Note
There are many other possible hyperparameters to search over. In particular, the scikit-learn documentation for random forest indicates that "The main parameters to adjust when using these methods are
n_estimators
andmax_features
" and that "Empirical good default values are …max_features=sqrt(n_features)
for classification tasks."Source: https://scikit-learn.org/stable/modules/ensemble.html...