Data Science Desktop Survival Guide
by Graham Williams |
|||||
Rules Using Rpart Plot |
We can also use rpart.plot::rpart.rules() from Stephen Milborrow's excellent rpart.plot package. This will convert the decision tree into rules:
rpart.rules(model)
Some variations appear below. The first adds the coverage of the rule, which is the percentage of the training dataset that ends up in this part of the decision tree. The second adds the proportions of observations within a leaf node that correspond to No/Yes.
|
rpart.rules(model, cover=TRUE)
rpart.rules(model, extra=4)
We can even obtain an explanation of the rules used in a prediction. Here we select specific observations to obtain the prediction and the rule used to make that prediction.
|
rpart.predict(model, newdata=ds[c(10, 12, 17), vars], rules=TRUE)
|