Exercise

Pruning the tree with the loss matrix

In this exercise, you will prune the tree that was built using a loss matrix in order to penalize misclassified defaults more than misclassified non-defaults.

Instructions

100 XP
  • Run the code to set a seed and construct tree_loss_matrix again.
  • Use function plotcp() to examine the cross-validated error-structure.
  • Looking at the cp-plot, you will notice that pruning the tree using the minimum cross-validated error will lead to a tree that is as big as the unpruned tree, as the cross-validated error reaches its minimum for cp = 0.001. Because you would like to make the tree somewhat smaller, try pruning the tree using cp = 0.0012788. For this complexity parameter, the cross-validated error approaches the minimum observed error. Call the pruned tree ptree_loss_matrix.
  • Package rpart.plot is loaded in your workspace. Plot the pruned tree using function prp() (including argument extra = 1).