Code
library(tidyverse)
full_model <-
glm(default ~ ., data=ISLR2::Default, family=binomial)
set.seed(40)
sample_customers <-
ISLR2::Default %>%
slice(9986, 9908, 6848, 9762, 9979, 7438)
pred <- predict(full_model, sample_customers, type="response")
# Format it as percentage
sample_customers$prediction <-
sapply(pred, function(x){sprintf("%.2f %%", 100*x)})
sample_customers
default student balance income prediction
1 No No 842.9494 39957.13 0.27 %
2 No No 1500.5721 39891.86 10.53 %
3 Yes Yes 1957.1203 18805.95 44.23 %
4 No No 1902.1499 35008.67 53.71 %
5 Yes No 2202.4624 47287.26 87.09 %
6 Yes Yes 2461.5070 11878.56 93.34 %