MulaiMulai sekarang secara gratis

The best performing parameter

You've now built models where you've varied the random forest-specific hyperparameter mtry in the hopes of improving your model further. Now you will measure the performance of each mtry value across the 5 cross validation partitions to see if you can improve the model.

Remember that the validate MAE you calculated two exercises ago of 0.795 was for the default mtry value of 2.

Latihan ini adalah bagian dari kursus

Machine Learning in the Tidyverse

Lihat Kursus

Petunjuk latihan

  • Generate predictions for each mtry/fold combination.
  • Calculate the MAE for each mtry/fold combination.
  • Calculate the mean MAE for each value of mtry.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Generate validate predictions for each model
cv_prep_tunerf <- cv_model_tunerf %>% 
  mutate(validate_predicted = map2(.x = ___, .y = ___, ~predict(.x, .y)$predictions))

# Calculate validate MAE for each fold and mtry combination
cv_eval_tunerf <- cv_prep_tunerf %>% 
  mutate(validate_mae = map2_dbl(.x = ___, .y = ___, ~mae(actual = .x, predicted = .y)))

# Calculate the mean validate_mae for each mtry used  
cv_eval_tunerf %>% 
  group_by(___) %>% 
  summarise(mean_mae = mean(___))
Edit dan Jalankan Kode