Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

rpart.predict

Extended version of predict.rpart


Description

Identical to predict.rpart but optionally show the node numbers and rules for the predicted values.

Usage

rpart.predict(object, newdata,
              type = c("vector", "prob", "class", "matrix"),
              na.action = na.pass,
              nn=FALSE, rules=FALSE, ...)

Arguments

object, newdata, type, na.action

Identical to the same arguments for predict.rpart.
If both nn and rules are FALSE, the returned value is identical to predict.rpart.

nn

If TRUE, return a data.frame with the predictions as usual but with an extra column showing the leaf node number for each prediction.

rules

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.
It may be helpful to use options(width=1000) before printing this data.frame.

...

Passed on to rpart.rules, for example clip.facs=TRUE.

Value

Same as predict.rpart, but with additional information if nn=TRUE and/or rules=TRUE.

See Also

Examples

data(ptitanic)
model <- rpart(survived ~ ., data = ptitanic, cp = .02)
head(rpart.predict(model, rules=TRUE))

rpart.plot

Plot 'rpart' Models: An Enhanced Version of 'plot.rpart'

v3.0.9
GPL-3
Authors
Stephen Milborrow
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.