Search for the optimal tree
In this exercise, you'll perform grid search using 5-fold cross validation to find dt
's optimal hyperparameters. Note that because grid search is an exhaustive 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)
An untuned classification tree dt
as well as the dictionary params_dt
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 5-fold CV by setting the parameters:estimator
todt
,param_grid
toparams_dt
andscoring
to'roc_auc'
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import GridSearchCV
____
# Instantiate grid_dt
grid_dt = ____(estimator=____,
param_grid=____,
scoring=____,
cv=____,
n_jobs=-1)