MulaiMulai sekarang secara gratis

Implementing GridSearch

You can now use the sklearn GridSearchCV() function to find the best combination of all of the max_depth and min_samples_leaf values you generated in the previous exercise.

Latihan ini adalah bagian dari kursus

HR Analytics: Predicting Employee Churn in Python

Lihat Kursus

Petunjuk latihan

  • Import the GridSearchCV function
  • Apply a GridSearchCV() function to your model using the parameters dictionary you defined earlier. Save this as param_search.
  • Fit param_search to the training dataset.
  • Print the best parameters found using best_params_ attribute.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# import the GridSearchCV function
from sklearn.model_selection import ____

# set up parameters: done
parameters = dict(max_depth=depth, min_samples_leaf=samples)

# initialize the param_search function using the GridSearchCV function, initial model and parameters above
param_search = ____(model, parameters, cv=3)

# fit the param_search to the training dataset
____.fit(features_train, target_train)

# print the best parameters found
print(param_search.____)
Edit dan Jalankan Kode