Get startedGet started for free

Prepare for cross-validated performance

Now that you know how to calculate the performance metrics for a single model, you are now ready to expand this for all the folds in the cross-validation data frame.

This exercise is part of the course

Machine Learning in the Tidyverse

View Course

Exercise instructions

  • Add the validate_actual binary column for each cross-validation fold by converting all "Yes" values to TRUE.
  • Use model to predict the probabilities of attrition for each cross-validation fold of validate. Convert the predicted probabilities to a binary vector, treating all probabilities greater than 0.5 as TRUE. Name this column validate_predicted.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

cv_prep_lr <- cv_models_lr %>% 
  mutate(
    # Prepare binary vector of actual Attrition values in validate
    validate_actual = map(validate, ~.x$___ == "___"),
    # Prepare binary vector of predicted Attrition values for validate
    validate_predicted = map2(.x = ___, .y = ___, ~predict(.x, .y, type = "response") > ___)
  )
Edit and Run Code