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 ...