Learn R Programming

itree (version 0.1)

predict.itree: Predictions from a Fitted itree Object

Description

Returns a vector of predicted responses from a fitted itree object. This function is used and functions identically to predict.rpart even for procedures unique to itree. However itree does not currently support the type="matrix" option.

Usage

## S3 method for class 'itree':
predict(object, newdata = list(),
       type = c("vector", "prob", "class", "matrix"),
       na.action = na.pass, ...)

Arguments

Value

A new object is obtained by dropping 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 prediction.

If 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). If type="prob": (for a classification tree) a matrix of class probabilities.

If type="matrix": For regression trees, this is the mean response, and for classification trees it is the concatenation of the predicted class, the class counts at that node in the fitted tree, and the class probabilities.

If type="class": (for a classification tree) a factor of classifications based on the responses.

Details

This function is a method for the generic function predict for class itree. It can be invoked by calling predict for an object of the appropriate class, or directly by calling predict.itree regardless of the class of the object.

See Also

predict, itree.object

Examples

Run this code
#verbatim from rpart examples:
z.auto <- itree(Mileage ~ Weight, car.test.frame)
predict(z.auto)

fit <- itree(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 <- itree(Species ~ ., data=iris, subset=sub)
fit
table(predict(fit, iris[-sub,], type="class"), iris[-sub, "Species"])

Run the code above in your browser using DataLab