Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Challenge: Automatic Hyperparameter Tuning | Conclusion
Introduction to Neural Networks with Python
セクション 3.  3
single

single

bookChallenge: Automatic Hyperparameter Tuning

メニューを表示するにはスワイプしてください

Rather than manually selecting specific values for our model's hyperparameters, randomized search (RandomizedSearchCV) offers a more efficient way to find an optimal configuration. Unlike grid search (GridSearchCV), which systematically evaluates all possible combinations of hyperparameters, randomized search selects a random subset of these combinations. This approach significantly reduces computational cost while still yielding strong results.

For neural networks, where the number of possible hyperparameter combinations can be immense, exhaustively testing every option is often impractical. Randomized search circumvents this issue by randomly sampling a defined number of hyperparameter sets, balancing exploration and efficiency.

RandomizedSearchCV(
    estimator=model, 
    param_distributions=randomized_parameters, 
    n_iter=number_of_models_to_test,  # Number of random combinations to evaluate
    scoring='accuracy',  # Evaluation metric
    random_state=42,  # Ensures reproducibility
)
  • estimator: the model to optimize (e.g., MLPClassifier);
  • param_distributions: a dictionary where keys are hyperparameter names and values are lists which to sample;
  • n_iter: specifies how many random combinations should be tested. A higher value increases the chances of finding an optimal combination but requires more computation;
  • scoring: defines the evaluation metric (e.g., 'accuracy' for classification).
タスク

スワイプしてコーディングを開始

Your goal is to tune the hyperparameters of a multilayer perceptron (MLP) using the RandomizedSearchCV method from scikit-learn.

Follow these steps carefully:

  1. Define the parameter grid param_distributions:
    • 'hidden_layer_sizes': include three configurations — (20, 20), (25, 25), and (30, 30);
    • 'learning_rate_init': include values 0.02, 0.01, and 0.005;
    • 'max_iter': include values 10, 30, and 50.
  2. Initialize the model using MLPClassifier().
  3. Apply RandomizedSearchCV:
    • Use the defined mlp model as the estimator;
    • Use the defined param_distributions grid;
    • Set n_iter=4 to limit the number of parameter combinations;
    • Use 'accuracy' as the evaluation metric;
    • Set random_state=1 for reproducibility.
  4. Fit the randomized search on the training data and print the best parameters found.
  5. Train the best model on the full training data and evaluate its accuracy on both the training and test sets.

解答

Switch to desktop実践的な練習のためにデスクトップに切り替える下記のオプションのいずれかを利用して、現在の場所から続行する
すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 3.  3
single

single

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

some-alt