8.37 Evaluate the model

Confusion matrix (train)

augment(class_tree_fit, new_data = carseats_train) %>% 
     conf_mat(truth = High, estimate = .pred_class)
##           Truth
## Prediction  No Yes
##        No  159  17
##        Yes  18 106
augment(class_tree_fit, new_data = carseats_train) %>% 
     accuracy(truth = High, estimate = .pred_class)
## # A tibble: 1 × 3
##   .metric  .estimator .estimate
##   <chr>    <chr>          <dbl>
## 1 accuracy binary         0.883

Training accuracy: 88.3%

Confusion matrix (test)

augment(class_tree_fit, new_data = carseats_test) %>%
  conf_mat(truth = High, estimate = .pred_class)
##           Truth
## Prediction No Yes
##        No  39   7
##        Yes 20  34
augment(class_tree_fit, new_data = carseats_test) %>% 
     accuracy(truth = High, estimate = .pred_class)
## # A tibble: 1 × 3
##   .metric  .estimator .estimate
##   <chr>    <chr>          <dbl>
## 1 accuracy binary          0.73

Testing accuracy: 73% (overfit)