predict.randomForest {randomForest}R Documentation

predict method for random forest objects

Description

Prediction of test data using random forest.

Usage

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 "response", for backward compatibility.
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:

response predicted classes (the classes with majority vote).
prob matrix of class probabilities (one column for each class and one row for each input).
votes matrix 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.

Author(s)

Andy Liaw andy_liaw@merck.com and Matthew Wiener matthew_wiener@merck.com, based on original Fortran code by Leo Breiman and Adele Cutler.

References

Breiman, L. (2001), Random Forests, Machine Learning 45(1), 5-32.

See Also

randomForest

Examples

data(iris)
set.seed(111)
ind <- sample(2, nrow(iris), replace = TRUE, prob=c(0.8, 0.2))
iris.rf <- randomForest(Species ~ ., data=iris[ind == 1,])
iris.pred <- predict(iris.rf, iris[ind == 2,])
table(observed = iris[ind==2, "Species"], predicted = iris.pred)

[Package Contents]