randomForest (version 3.3-4)

predict.randomForest: predict method for random forest objects

Description

Prediction of test data using random forest.

Usage

## S3 method for class 'randomForest':
predict(object, newdata, type="response",
  norm.votes=TRUE, proximity=FALSE, ...)

Arguments

object
an object of class randomForest, as that created by the function randomForest.
newdata
a data frame or matrix containing new data.
type
one of response, prob. or votes, indicating the type of output: predicted values, matrix of class probabilities, or matrix of vote counts. class is allowed, but automatically converted to "respons
norm.votes
Should the vote counts be normalized (i.e., expressed as fractions)? Ignored if object$type is regression.
proximity
Should proximity measures be computed? An error is issued if object$type is regression.
...
not used currently.

Value

  • If object$type is regression, a vector of predicted values is returned.

    If object$type is classification, the vector returned depends on the argument type:

  • responsepredicted classes (the classes with majority vote).
  • probmatrix of class probabilities (one column for each class and one row for each input).
  • votesmatrix of vote counts (one column for each class and one row for each new input); either in raw counts or in fractions (if norm.votes=TRUE).
  • If proximity=TRUE, the returned object is a list with two components: pred is the prediction (as described above) and proximity is the proximitry matrix. An error is issued if object$type is regression.

References

Breiman, L., Random Forests, http://oz.berkeley.edu/users/breiman/randomforest2001.pdf.

See Also

randomForest

Examples

Run this code
data(iris)
set.seed(111)
n.iris <- nrow(iris)
iris.test <- sample(n.iris, round(n.iris/3), replace=FALSE)
iris.rf <- randomForest(Species ~ ., data=iris[-iris.test,])
iris.pred <- predict(iris.rf, iris[iris.test,])
table(observed = iris[iris.test,"Species"], predicted = iris.pred)

Run the code above in your browser using DataLab