IniziaInizia gratis

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.

Questo esercizio fa parte del corso

Machine Learning with Tree-Based Models in Python

Visualizza il corso

Istruzioni dell'esercizio

  • Import GridSearchCV from sklearn.model_selection.

  • Instantiate a GridSearchCV object using 5-fold CV by setting the parameters:

    • estimator to dt, param_grid to params_dt and

    • scoring to 'roc_auc'.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

# Import GridSearchCV
____

# Instantiate grid_dt
grid_dt = ____(estimator=____,
                       param_grid=____,
                       scoring=____,
                       cv=____,
                       n_jobs=-1)
Modifica ed esegui il codice