After fitting a scikit-learn GridSearchCV on Databricks, how do you access the best hyperparameter combination found?
Select an answer to reveal the explanation.
Short Explanation and Infographic
scikit-learn follows a convention where fitted attributes end with an underscore — grid_search.best_params_ is the dict of the winning hyperparameter combination after fitting.
Full explanation below image
Full Explanation
After grid_search = GridSearchCV(estimator, param_grid, cv=5); grid_search.fit(X_train, y_train): grid_search.best_params_ — dict of best hyperparameter values, e.g., {'max_depth': 5, 'n_estimators': 100}. grid_search.best_score_ — mean cross-validation score of the best estimator. grid_search.best_estimator_ — the best fitted estimator (already refit on the full training set if refit=True). grid_search.cv_results_ — dict with detailed results for all parameter combinations (mean_test_score, std_test_score, params for each combination). The underscore suffix convention in scikit-learn indicates attributes that are computed during fit() (not set by the user). grid_search.best_parameters (no underscore) would be an AttributeError. get_best_params() is not a method. cv_results_['best_params'] doesn't exist as a key — cv_results_['params'] is a list of all parameter dicts.