IniziaInizia 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.

Questo esercizio fa parte del corso

Machine Learning in the Tidyverse

Visualizza il corso

Istruzioni dell'esercizio

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

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

# 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(___))
Modifica ed esegui il codice