Decision tree for german data
We have fit a logistic regression model for the German data. Now, we will create a decision tree for it.
Getting ready
The GC2
object along with the partitioned data will be required here. Also, the fitted logistic regression model is needed.
How to do it ...
We will create the decision tree using the rpart
package and its functionalities:
- Create the decision tree and plot it as follows:
GC_CT <- rpart (good_bad~., data= GC_Train) windows ( height= 20 , width= 20 ) plot (GC_CT, uniform = TRUE ); text (GC_CT)
- The decision tree plot is given as follows:

- The properties of the fitted tree need to be evaluated.
- Check the complexity parameter and important variables of the fitted tree:
table (GC_Train$good_bad, predict (GC_CT, type= "class" )) ## ## bad good ## bad 107 74 ## good 32 386 GC_CT$cptable ## CP nsplit rel error xerror xstd ## 1 0.06262 0 1.0000 1.0000 0.06209 ## 2 0.02486 3 0.8122 0.9503 0.06118 ## 3 0.02210 6 0.7348 1.0055 0.06219...