CommencerCommencer gratuitement

Build & evaluate the best model

Using cross-validation you were able to identify the best model for predicting life_expectancy using all the features in gapminder. Now that you've selected your model, you can use the independent set of data (testing_data) that you've held out to estimate the performance of this model on new data.

You will build this model using all training_data and evaluate using testing_data.

Cet exercice fait partie du cours

Machine Learning in the Tidyverse

Afficher le cours

Instructions

  • Use ranger() to build the best performing model (mtry = 4) using all of the training data. Assign this to best_model.
  • Extract the life_expectancy column from testing_data and assign it to test_actual.
  • Predict life_expectancy using the best_model on the testing data and assign it to test_predicted.
  • Calculate the MAE using test_actual and test_predicted vectors.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Build the model using all training data and the best performing parameter
best_model <- ranger(formula = ___, data = ___,
                     mtry = ___, num.trees = 100, seed = 42)

# Prepare the test_actual vector
test_actual <- testing_data$___

# Predict life_expectancy for the testing_data
test_predicted <- predict(___, ___)$predictions

# Calculate the test MAE
mae(___, ___)
Modifier et exécuter le code