Search for the optimal forest
In this exercise, you'll perform grid search using 3-fold cross validation to find rf
's optimal hyperparameters. To evaluate each model in the grid, you'll be using the negative mean squared error metric.
Note that because grid search is an exhaustive search process, it may take a lot time to train the model. Here you'll only be instantiating the GridSearchCV
object without fitting it to the training set. As discussed in the video, you can train such an object similar to any scikit-learn estimator by using the .fit()
method:
grid_object.fit(X_train, y_train)
The untuned random forests regressor model rf
as well as the dictionary params_rf
that you defined in the previous exercise are available in your workspace.
This exercise is part of the course
Machine Learning with Tree-Based Models in Python
Exercise instructions
Import
GridSearchCV
fromsklearn.model_selection
.Instantiate a
GridSearchCV
object using 3-fold CV by using negative mean squared error as the scoring metric.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import GridSearchCV
____
# Instantiate grid_rf
grid_rf = ____(estimator=____,
param_grid=____,
scoring=____,
cv=____,
verbose=1,
n_jobs=-1)