Returns a vector of predicted responses from a fitted
1 2 3 4
fitted model object of class
data frame containing the values at which predictions are required.
The predictors referred to in the right side of
character string denoting the type of predicted value returned. If
a function to determine what should be done with
missing values in
further arguments passed to or from other methods.
This function is a method for the generic function predict for class
"rpart". It can be invoked by calling
predict for an object
of the appropriate class, or directly by calling
regardless of the class of the object.
A new object is obtained by
newdata down the object. For factor predictors, if an
observation contains a level not used to grow the tree, it is left at
the deepest possible node and
frame$yval at the node is the
type = "vector":
vector of predicted responses. For regression trees this is the mean response at the node, for Poisson trees it is the estimated response rate, and for classification trees it is the predicted class (as a number).
type = "prob":
(for a classification tree) a matrix of class probabilities.
type = "matrix":
a matrix of the full responses (
frame$yval2 if this exists, otherwise
regression trees, this is the mean response, for Poisson trees it is
the response rate and the number of events at that node in the fitted
tree, and for classification trees it is the concatenation of at least
the predicted class, the class counts at that node in the fitted tree,
and the class probabilities (some versions of rpart may contain
type = "class":
(for a classification tree) a factor of classifications based on the responses.
1 2 3 4 5 6 7 8 9 10 11 12 13
z.auto <- rpart(Mileage ~ Weight, car.test.frame) predict(z.auto) fit <- rpart(Kyphosis ~ Age + Number + Start, data = kyphosis) predict(fit, type = "prob") # class probabilities (default) predict(fit, type = "vector") # level numbers predict(fit, type = "class") # factor predict(fit, type = "matrix") # level number, class frequencies, probabilities sub <- c(sample(1:50, 25), sample(51:100, 25), sample(101:150, 25)) fit <- rpart(Species ~ ., data = iris, subset = sub) fit table(predict(fit, iris[-sub,], type = "class"), iris[-sub, "Species"])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.