Session Ready
Exercise

Building and plotting rpart() models

It was noted in the video that decision trees represent a popular form of predictive model because they are easy to visualize and explain. It was also noted that the rpart package is probably the most popular of several R packages that can be used to build and visualize these models.

This exercise asks you to, first, build a decision tree model using the rpart() function from this package, and then display the resulting model structure using the generic functions plot() and text().

Instructions
100 XP
  • Load the rpart package to make the rpart() modeling function and the associated methods for generic functions like plot() available.
  • Use the rpart() function to fit a decision tree model tree_model that predicts medv in the Boston data frame from all of the other variables in this data frame.
  • Apply the plot() function to tree_model to obtain an unlabelled plot of the structure of this decision tree model.
  • Apply the text() function to tree_model to label this plot. To make the labels easier to read, use the cex parameter to reduce the text to 70% of the default size.