How to do it...

Perform the following steps to split the churn dataset into training and testing datasets:

  1. Load the rpart package:
        > library(rpart)  
  1. Use the rpart function to build a classification tree model:
        > churn.rp = rpart(churn ~ ., data=trainset)  
  1. Type churn.rp to retrieve the node detail of the classification tree:
        > churn.rp   
  1. Next, use the printcp function to examine the complexity parameter:
        > printcp(churn.rp)
Output

Classification tree:
rpart(formula = churn ~ ., data = trainset)

Variables actually used in tree construction:
[1] international_plan number_customer_service_calls
[3] total_day_minutes total_eve_minutes
[5] total_intl_calls total_intl_minutes
[7] voice_mail_plan

Root node error: 342/2315 = 0.14773

n= 2315

CP nsplit rel error xerror xstd
1 0.076023 0 1.00000 1.00000 0.049920
2 0.074561 2 0.84795 0.99708 0.049860
3 0.055556 4 0.69883 0.76023 0.044421
4 0.026316 7 0.49415 0.52632 0.037673
5 0.023392 8 0.46784 0.52047 0.037481
6 0.020468 10 0.42105 0.50877 0.037092
7 0.017544 11 0.40058 0.47076 0.035788
8 0.010000 12 0.38304 0.47661 0.035993
  1. Next, use the plotcp function to plot the cost complexity parameters:
        > plotcp(churn.rp)  
The cost complexity parameter plot
  1. Lastly, use the summary function to examine the built model:
        > summary(churn.rp)  
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset