Building a classification model with recursive partitioning trees
A classification tree uses a split condition to predict class labels based on one or multiple input variables. The classification process starts from the root node of the tree; at each node, the process will check whether the input value should recursively continue to the right or left sub-branch according to the split condition, and stops when meeting any leaf (terminal) nodes of the decision tree. In this recipe, we will introduce how to apply a recursive partitioning tree on the customer churn
dataset.
Getting ready
You need to have completed the previous recipe by splitting the churn dataset into the training dataset (trainset
) and testing dataset (testset
), and each dataset should contain exactly 17 variables.
How to do it...
Perform the following steps to split the churn dataset into training and testing datasets:
- Load the
rpart
package:
> library(rpart)
- Use the
rpart
function to build a classification tree model:
...