Building regression trees
This recipe covers the use of tree models for regression. The
rpart package provides the necessary functions to build regression trees.
rpart.plot packages if you do not already have them installed. If you have not already downloaded the data files for this chapter, do so now and ensure that the
education.csv files are in the R working directory.
How to do it...
To build regression trees, follow the steps below:
- Load the
> library(rpart) > library(rpart.plot) > library(caret)
- Read the data:
> bh <- read.csv("BostonHousing.csv")
- Partition the data:
> set.seed(1000) > t.idx <- createDataPartition(bh$MEDV, p=0.7, list = FALSE) ...