Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Hyperparameter Tuning with Tune | Section
Predictive Modeling with Tidymodels in R
セクション 1.  8
single

single

bookHyperparameter Tuning with Tune

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

Hyperparameters are adjustable parameters that govern the training process of a model but are not learned from the data itself. These include settings like the number of trees in a random forest, the maximum depth of a decision tree, or the penalty term in regularized regression. Selecting appropriate hyperparameter values is crucial because they can significantly influence model performance. If set too high or too low, hyperparameters may cause overfitting or underfitting, leading to poor generalization on new data.

123456789101112131415161718192021222324252627282930313233343536
options(crayon.enabled = FALSE) library(tidymodels) tree_spec <- decision_tree( tree_depth = tune(), min_n = tune() ) %>% set_engine("rpart") %>% set_mode("classification") # Create a workflow tree_workflow <- workflow() %>% add_model(tree_spec) %>% add_formula(Species ~ .) # Define a grid of hyperparameters to search over tree_grid <- grid_regular( tree_depth(range = c(1, 5)), min_n(range = c(2, 10)), levels = 3 ) # Set up cross-validation folds set.seed(123) cv_folds <- vfold_cv(iris, v = 5) # Perform grid search tuning tune_results <- tune_grid( tree_workflow, resamples = cv_folds, grid = tree_grid, metrics = metric_set(accuracy) ) # Review the tuning results print(collect_metrics(tune_results))
copy

During hyperparameter tuning, it is important to use cross-validation to estimate model performance for each hyperparameter combination. This helps avoid overfitting to a single train-test split and provides a more robust assessment of how the model will perform on unseen data. Once tuning is complete, you can select the best model based on the performance metric most relevant to your problem, such as accuracy for classification or RMSE for regression. The selected model can then be finalized and retrained on the entire training set before being evaluated on the test set.

タスク

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

Perform hyperparameter tuning for a decision tree classification model using a provided grid.

  • The decision tree specification, workflow, hyperparameter grid, and cross-validation folds are already set up for you.
  • Utilize the tune_grid() function to search over the hyperparameter grid. Pass the workflow, cross-validation folds (resamples), the grid, and specify metrics = metric_set(accuracy).
  • Select the best hyperparameter combination based on accuracy utilizing the select_best() function.
  • Assign the best result to best_result and print it.

解答

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

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

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

セクション 1.  8
single

single

AIに質問する

expand

AIに質問する

ChatGPT

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

some-alt