ComeçarComece de graça

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.

Este exercício faz parte do curso

HR Analytics: Predicting Employee Churn in Python

Ver curso

Instruções do exercício

  • 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.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# 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.____)
Editar e executar o código