## S3 method for class 'randomForest':
predict(object, newdata, type="response",
norm.votes=TRUE, predict.all=FALSE, proximity=FALSE, nodes=FALSE,
cutoff, ...)randomForest, as that
created by the function randomForest.object is returned.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 "responsobject$type is
regression.object$type is regression.forest$cutoff component ofobject$type is regression, a vector of predicted
values is returned. If predict.all=TRUE, then the returned
object is a list of two components: aggregate, which is the
vector of predicted values by the forest, and individual, which
is a matrix where each column contains prediction by a tree in the
forest. If object$type is classification, the object returned
depends on the argument type:
norm.votes=TRUE).predict.all=TRUE, then the individual component of the
returned object is a character matrix where each column contains the
predicted class by a tree in the forest.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.
If nodes=TRUE, the returned object has a ``nodes'' attribute,
which is an n by ntree matrix, each column containing the node number
that the cases fall in for that tree.
randomForestdata(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)Run the code above in your browser using DataLab