Building, plotting, and evaluating – classification trees
You can use a couple of R packages to build classification trees. Under the hood, they all do the same thing.
If you do not already have the
caret packages, install them now. Download the data files for this chapter from the book's website and place the
banknote-authentication.csv file in your R working directory.
How to do it...
This recipe shows you how you can use the
rpart package to build classification trees and the
rpart.plot package to generate nice-looking tree diagrams:
- Load the
> library(rpart) > library(rpart.plot) > library(caret)
- Read the data:
> bn <- read.csv("banknote-authentication.csv")
- Create data partitions. ...