Returns a vector of predicted responses from a fitted tree object.
## S3 method for class 'tree' predict(object, newdata = list(), type = c("vector", "tree", "class", "where"), split = FALSE, nwts, eps = 1e-3, ...)
fitted model object of class
data frame containing the values at which predictions are required.
The predictors referred to in the right side
character string denoting whether the predictions are returned as a vector (default) or as a tree object.
governs the handling of missing values. If false, cases with missing
values are dropped down the tree until a leaf is reached or a node
for which the attribute is missing, and that node is used for
weights for the
a lower bound for the probabilities, used if events of predicted
probability zero occur in
further arguments passed to or from other methods.
This function is a method for the generic function
predict() for class
It can be invoked by calling
predict(x) for an
x of the appropriate class, or directly by
predict.tree(x) regardless of the
class of the object.
type = "vector":
vector of predicted responses or, if the response is a factor, matrix
of predicted class probabilities. This new object is obtained by
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$yprob at that
node is the prediction.
type = "tree":
an object of class
"tree" is returned with new values
newdata does not contain a column for the response in the formula
the value of
frame$dev will be
NA, and if some values in the
response are missing, the some of the deviances will be
type = "class":
for a classification tree, a factor of the predicted classes (that
with highest posterior probability, with ties split randomly).
type = "where":
the nodes the cases reach.
Ripley, B. D. (1996). Pattern Recognition and Neural Networks. Cambridge University Press, Cambridge. Chapter 7.
data(shuttle, package="MASS") shuttle.tr <- tree(use ~ ., shuttle, subset=1:253, mindev=1e-6, minsize=2) shuttle.tr shuttle1 <- shuttle[254:256, ] # 3 missing cases predict(shuttle.tr, shuttle1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.