Skip to main content

Section 9.8 Make Predictions

Before, we took our data and split it into a training set and a test set. Using the training set, we built a logistic regression model. Now that we have it, it is time to test it against our test data!
As previously stated, it is best to test our model against real data, because we then get to compare and contrast what our model predicted vs what actually happened. It is now time to do exactly that!
We are going to create two new columns in our test data:
  1. pred_prob: Our model is going to predict the likelihood of someone defaulting, using that row’s data.
  2. pred_class: based on the probability from pred_prob, it is going to either be β€œYes” or β€œNo.”
test_data$pred_prob <- predict(train_model, newdata = test_data, type = "response")

test_data$pred_class <- ifelse(test_data$pred_prob > 0.5, "Yes", "No") |> as.factor()
In the above code, we used 0.5 as our cutoff for deciding if a person defaulted or not. 0.5 is a good measure since it is at the halfway point, but it is up to you to decide what the marker should be.
With this code complete, our model has now churned out the results (if someone will or will not default on their credit card).