Challenge: Tuning Hyperparameters with RandomizedSearchCV
ã¡ãã¥ãŒã衚瀺ããã«ã¯ã¹ã¯ã€ãããŠãã ãã
RandomizedSearchCV works like GridSearchCV, but instead of checking every hyperparameter combination, it evaluates a random subset.
In the example below, the grid contains 100 combinations. GridSearchCV tests all of them, while RandomizedSearchCV can sample, for example, 20 â controlled by n_iter. This makes tuning faster, while usually finding a score close to the best.
ã¹ã¯ã€ãããŠã³ãŒãã£ã³ã°ãéå§
You have a preprocessed penguin dataset. Tune a KNeighborsClassifier using both search methods:
- Create
param_gridwith values forn_neighbors,weights, andp. - Initialize
RandomizedSearchCV(..., n_iter=20). - Initialize
GridSearchCVwith the same grid. - Fit both searches on
X, y. - Print the grid searchâs
.best_estimator_. - Print the randomized searchâs
.best_score_.
è§£ç
Try running the code multiple times. RandomizedSearchCV may match the grid search score when it randomly samples the best hyperparameters.
ãã£ãŒãããã¯ããããšãããããŸãïŒ
single
AIã«è³ªåãã
AIã«è³ªåãã
äœã§ã質åããããææ¡ããã質åã®1ã€ã詊ããŠãã£ãããå§ããŠãã ãã