Modeling in R

In this example, we will use the rpart package, which is used to build a decision tree. The tree with the minimum prediction error is selected. After that, the tree is applied to make predictions for unlabeled data with the predict function.

One way to call rpart is to give it a list of variables and see what happens. Although we have discussed missing values, rpart has built-in code for dealing with missing values. So let's dive in, and look at the code.

Firstly, we need to call the libraries that we need:


Next, let's load in the data, which will be in the AdultUCI variable:

## 75% of the sample size
sample_size <- floor(0.80 ...

Get Advanced Analytics with R and Tableau now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.