MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Machine Learning with Tree-Based Models in Python

Lihat Kursus

Petunjuk latihan

  • Import GridSearchCV from sklearn.model_selection.

  • Instantiate a GridSearchCV object using 3-fold CV by using negative mean squared error as the scoring metric.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Import GridSearchCV
____

# Instantiate grid_rf
grid_rf = ____(estimator=____,
                       param_grid=____,
                       scoring=____,
                       cv=____,
                       verbose=1,
                       n_jobs=-1)
Edit dan Jalankan Kode