Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Grid Search | Manual and Search-Based Tuning Methods
Hyperparameter Tuning Basics

bookChallenge: Grid Search

Opgave

Swipe to start coding

In this challenge, you will apply grid search to automatically find the best hyperparameters for a RandomForestClassifier.

You'll use a noisy two-class dataset generated with make_moons. Your task is to:

  1. Define the parameter grid param_grid:
    • 'n_estimators': [50, 100, 200]
    • 'max_depth': [3, 5, None]
    • 'min_samples_split': [2, 4]
  2. Create a GridSearchCV object using:
    • The model: RandomForestClassifier(random_state=42)
    • The defined grid param_grid
    • cv=5 cross-validation folds
    • 'accuracy' as the scoring metric
  3. Fit the search object on the training data and print:
    • grid_search.best_params_
    • The test accuracy of the best model.

Løsning

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 2. Kapitel 4
single

single

Spørg AI

expand

Spørg AI

ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

close

Awesome!

Completion rate improved to 9.09

bookChallenge: Grid Search

Stryg for at vise menuen

Opgave

Swipe to start coding

In this challenge, you will apply grid search to automatically find the best hyperparameters for a RandomForestClassifier.

You'll use a noisy two-class dataset generated with make_moons. Your task is to:

  1. Define the parameter grid param_grid:
    • 'n_estimators': [50, 100, 200]
    • 'max_depth': [3, 5, None]
    • 'min_samples_split': [2, 4]
  2. Create a GridSearchCV object using:
    • The model: RandomForestClassifier(random_state=42)
    • The defined grid param_grid
    • cv=5 cross-validation folds
    • 'accuracy' as the scoring metric
  3. Fit the search object on the training data and print:
    • grid_search.best_params_
    • The test accuracy of the best model.

Løsning

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 2. Kapitel 4
single

single

some-alt