O'Reilly logo

R Data Analysis Cookbook - Second Edition by Kuntal Ganguly

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

Steps 1 and 2 load the required packages and read the data.

Step 3 partitions the data. Refer to the Creating random data partitions recipe in Chapter 2, What's In There? - Exploratory Data Analysis for more details. We set the random seed to enable you to match your results with those that we have displayed.

Step 4 uses the rpart function to build the tree model. It passes the formula as MEDV ~ . to indicate that MEDV is the outcome and that all the remaining variables will be predictors. It specifies data = bh[t.idx, ] to indicate that only the rows in the training partition should be used to build the model. It then prints the model details in textual form. The output shows information for the root node and subsequently ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required