Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Challenge: Tuning Hyperparameters with RandomizedSearchCV | Section
Machine Learning Foundations with Scikit-Learn
Seção 1. Capítulo 30
single

single

bookChallenge: Tuning Hyperparameters with RandomizedSearchCV

Deslize para mostrar o menu

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.

Tarefa

Deslize para começar a programar

You have a preprocessed penguin dataset. Tune a KNeighborsClassifier using both search methods:

  1. Create param_grid with values for n_neighbors, weights, and p.
  2. Initialize RandomizedSearchCV(..., n_iter=20).
  3. Initialize GridSearchCV with the same grid.
  4. Fit both searches on X, y.
  5. Print the grid search’s .best_estimator_.
  6. Print the randomized search’s .best_score_.

Solução

Note
Note

Try running the code multiple times. RandomizedSearchCV may match the grid search score when it randomly samples the best hyperparameters.

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 30
single

single

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

some-alt