Identical to predict.rpart but optionally show the node numbers and rules for the predicted values.
predict.rpart
rpart.predict(object, newdata, type = c("vector", "prob", "class", "matrix"), na.action = na.pass, nn=FALSE, rules=FALSE, ...)
Identical to the same arguments for predict.rpart. If both nn and rules are FALSE, the returned value is identical to predict.rpart.
nn
rules
FALSE
If TRUE, return a data.frame with the predictions as usual but with an extra column showing the leaf node number for each prediction.
TRUE
data.frame
If TRUE, return a data.frame with the predictions as usual but with an extra column showing the rpart rule (as a string) for each prediction.
Passed on to rpart.rules, for example clip.facs=TRUE.
rpart.rules
clip.facs=TRUE
Same as predict.rpart, but with additional information if nn=TRUE and/or rules=TRUE.
nn=TRUE
rules=TRUE
predict.rpart rpart.rules
# NOT RUN { data(ptitanic) model <- rpart(survived ~ ., data = ptitanic, cp = .02) head(rpart.predict(model, rules=TRUE)) # }
Run the code above in your browser using DataLab