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.
This exercise is part of the course
HR Analytics: Predicting Employee Churn in Python
Exercise instructions
- Import the
GridSearchCV
function - Apply a
GridSearchCV()
function to yourmodel
using theparameters
dictionary you defined earlier. Save this asparam_search
. - Fit
param_search
to the training dataset. - Print the best parameters found using
best_params_
attribute.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# 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.____)