October 2018
Intermediate to advanced
172 pages
4h 6m
English
In this section, we will learn how to optimize the hyperparameters of the random forest algorithm. Since random forests are fundamentally based on multiple decision trees, the hyperparameters are very similar. In order to optimize the hyperparameters, we use the following code:
from sklearn.model_selection import GridSearchCV#Creating a grid of different hyperparametersgrid_params = { 'n_estimators': [100,200, 300,400,5000], 'max_depth': [1,2,4,6,8], 'min_samples_leaf': [0.05, 0.1, 0.2]}#Building a 3 fold Cross-Validated GridSearchCV objectgrid_object = GridSearchCV(estimator = rf_classifier, param_grid = grid_params, scoring = 'accuracy', cv = 3, n_jobs = -1)#Fitting the grid to the training ...Read now
Unlock full access