IniziaInizia gratis

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) and max_features ('auto' vs 'sqrt')
  • Use roc_auc to 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.

Questo esercizio fa parte del corso

Hyperparameter Tuning in Python

Visualizza il corso

Istruzioni dell'esercizio

  • Create a Random Forest estimator as specified in the context above.
  • Create a parameter grid as specified in the context above.
  • Create a GridSearchCV object as outlined in the context above, using the two elements created in the previous two instructions.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

# 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)
Modifica ed esegui il codice