Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Machine Learning in the Tidyverse

Cursus bekijken

Oefeninstructies

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

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# 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 <- ___
Code bewerken en uitvoeren