GridSearchCV with Scikit Learn
The GridSearchCV module from Scikit Learn provides many useful features to assist with efficiently undertaking a grid search. You will now put your learning into practice by creating a GridSearchCV object with certain parameters.
The desired options are:
- A Random Forest Estimator, with the split criterion as 'entropy'
- 5-fold cross validation
- The hyperparameters
max_depth(2, 4, 8, 15) andmax_features('auto' vs 'sqrt') - Use
roc_aucto score the models - Use 4 cores for processing in parallel
- Ensure you refit the best model and return training scores
You will have available X_train, X_test, y_train & y_test datasets.
Este ejercicio forma parte del curso
Hyperparameter Tuning in Python
Instrucciones del ejercicio
- Create a Random Forest estimator as specified in the context above.
- Create a parameter grid as specified in the context above.
- Create a
GridSearchCVobject as outlined in the context above, using the two elements created in the previous two instructions.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
# Create a Random Forest Classifier with specified criterion
rf_class = RandomForestClassifier(____=____)
# Create the parameter grid
param_grid = {____: ____, ____: ____}
# Create a GridSearchCV object
grid_rf_class = GridSearchCV(
estimator=____,
param_grid=____,
scoring=____,
n_jobs=____,
cv=____,
refit=____, return_train_score=____)
print(grid_rf_class)