Challenge: Tuning Hyperparameters with RandomizedSearchCV
The idea behind RandomizedSearchCV
is that it works the same as GridSearchCV
, but instead of trying all the combinations, it tries a randomly sampled subset.
For example, this param_grid
will have 100 combinations:
param_grid = {'n_neighbors': [1, 3, 5, 7, 9, 12, 15, 17, 20, 25],
'weights': ['distance', 'uniform'],
'p': [1, 2, 3, 4, 5]}
The GridSearchCV
would try all of them, which is time-consuming. With RandomizedSearchCV
, you can try only a randomly chosen subset of, say, 20 combinations. It usually leads to a little worse result, but works much faster.
You can control the number of combinations to be tested using the n_iter
argument (set to 10 by default). Apart from that, working with it is the same as with GridSearchCV
.
Swipe to start coding
Your task is to build GridSearchCV
and RandomizedSearchCV
with 20 combinations and compare the results.
- Initialize the
RandomizedSearchCV
object. Pass the parameters grid and set the number of combinations to 20. - Initialize the
GridSearchCV
object. - Train both
GridSearchCV
andRandomizedSearchCV
objects. - Print the best estimator of
grid
. - Print the best score of
randomized
.
Lösung
Danke für Ihr Feedback!
single
Fragen Sie AI
Fragen Sie AI
Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen
Awesome!
Completion rate improved to 3.13Awesome!
Completion rate improved to 3.13
Challenge: Tuning Hyperparameters with RandomizedSearchCV
The idea behind RandomizedSearchCV
is that it works the same as GridSearchCV
, but instead of trying all the combinations, it tries a randomly sampled subset.
For example, this param_grid
will have 100 combinations:
param_grid = {'n_neighbors': [1, 3, 5, 7, 9, 12, 15, 17, 20, 25],
'weights': ['distance', 'uniform'],
'p': [1, 2, 3, 4, 5]}
The GridSearchCV
would try all of them, which is time-consuming. With RandomizedSearchCV
, you can try only a randomly chosen subset of, say, 20 combinations. It usually leads to a little worse result, but works much faster.
You can control the number of combinations to be tested using the n_iter
argument (set to 10 by default). Apart from that, working with it is the same as with GridSearchCV
.
Swipe to start coding
Your task is to build GridSearchCV
and RandomizedSearchCV
with 20 combinations and compare the results.
- Initialize the
RandomizedSearchCV
object. Pass the parameters grid and set the number of combinations to 20. - Initialize the
GridSearchCV
object. - Train both
GridSearchCV
andRandomizedSearchCV
objects. - Print the best estimator of
grid
. - Print the best score of
randomized
.
Lösung
Danke für Ihr Feedback!
single
Awesome!
Completion rate improved to 3.13
Challenge: Tuning Hyperparameters with RandomizedSearchCV
Swipe um das Menü anzuzeigen
The idea behind RandomizedSearchCV
is that it works the same as GridSearchCV
, but instead of trying all the combinations, it tries a randomly sampled subset.
For example, this param_grid
will have 100 combinations:
param_grid = {'n_neighbors': [1, 3, 5, 7, 9, 12, 15, 17, 20, 25],
'weights': ['distance', 'uniform'],
'p': [1, 2, 3, 4, 5]}
The GridSearchCV
would try all of them, which is time-consuming. With RandomizedSearchCV
, you can try only a randomly chosen subset of, say, 20 combinations. It usually leads to a little worse result, but works much faster.
You can control the number of combinations to be tested using the n_iter
argument (set to 10 by default). Apart from that, working with it is the same as with GridSearchCV
.
Swipe to start coding
Your task is to build GridSearchCV
and RandomizedSearchCV
with 20 combinations and compare the results.
- Initialize the
RandomizedSearchCV
object. Pass the parameters grid and set the number of combinations to 20. - Initialize the
GridSearchCV
object. - Train both
GridSearchCV
andRandomizedSearchCV
objects. - Print the best estimator of
grid
. - Print the best score of
randomized
.
Lösung
Danke für Ihr Feedback!