Get startedGet started for free

Predictions of a single model

To calculate the performance of a classification model you need to compare the actual values of Attrition to those predicted by the model. When calculating metrics for binary classification tasks (such as precision and recall), the actual and predicted vectors must be converted to binary values.

In this exercise, you will learn how to prepare these vectors using the model and validate data frames from the first cross-validation fold as an example.

This exercise is part of the course

Machine Learning in the Tidyverse

View Course

Exercise instructions

  • Extract the model and the validate data frame from the first fold of the cross-validation.
  • Extract the Attrition column from the validate data frame and convert the values to binary (TRUE/FALSE).
  • Use model to predict the probabilities of attrition for the validate data frame.
  • Convert the predicted probabilities to a binary vector, assume all probabilities greater than 0.5 are TRUE.

Hands-on interactive exercise

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

# Extract the first model and validate 
model <- cv_models_lr$___[[___]]
validate <- cv_models_lr$___[[___]]

# Prepare binary vector of actual Attrition values in validate
validate_actual <- ___ == "Yes"

# Predict the probabilities for the observations in validate
validate_prob <- predict(___, ___, type = "response")

# Prepare binary vector of predicted Attrition values for validate
validate_predicted <- ___
Edit and Run Code