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 to 3 load the packages, read the data, and identify the cases in the training partition, respectively. See the Creating random data partitions recipe in Chapter 2, What's in There? - Exploratory Data Analysis, for more details on partitioning. In step 3, we set the random seed so that your results should match those that we display.

Step 4 builds the classification tree model:

> mod <- rpart(class ~ ., data = bn[train.idx, ], method = "class", control = rpart.control(minsplit = 20, cp = 0.01)) 

The rpart() function builds the tree model based on the following:

  • The formula specifying the dependent and independent variables
  • The dataset to use
  • A specification through method="class" that we want to build a classification ...

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