📄 predict.randomforest.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>R: predict method for random forest objects</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="../../R.css">
</head><body>
<table width="100%" summary="page for predict.randomForest {randomForest}"><tr><td>predict.randomForest {randomForest}</td><td align="right">R Documentation</td></tr></table>
<h2>predict method for random forest objects</h2>
<h3>Description</h3>
<p>
Prediction of test data using random forest.
</p>
<h3>Usage</h3>
<pre>
## S3 method for class 'randomForest':
predict(object, newdata, type="response",
norm.votes=TRUE, predict.all=FALSE, proximity=FALSE, nodes=FALSE,
cutoff, ...)
</pre>
<h3>Arguments</h3>
<table summary="R argblock">
<tr valign="top"><td><code>object</code></td>
<td>
an object of class <code>randomForest</code>, as that
created by the function <code>randomForest</code>.</td></tr>
<tr valign="top"><td><code>newdata</code></td>
<td>
a data frame or matrix containing new data. (Note: If
not given, the out-of-bag prediction in <code>object</code> is returned.</td></tr>
<tr valign="top"><td><code>type</code></td>
<td>
one of <code>response</code>, <code>prob</code>. or <code>votes</code>,
indicating the type of output: predicted values, matrix of class
probabilities, or matrix of vote counts. <code>class</code> is allowed, but
automatically converted to "response", for backward compatibility.</td></tr>
<tr valign="top"><td><code>norm.votes</code></td>
<td>
Should the vote counts be normalized (i.e.,
expressed as fractions)? Ignored if <code>object$type</code> is
<code>regression</code>.</td></tr>
<tr valign="top"><td><code>predict.all</code></td>
<td>
Should the predictions of all trees be kept?</td></tr>
<tr valign="top"><td><code>proximity</code></td>
<td>
Should proximity measures be computed? An error is
issued if <code>object$type</code> is <code>regression</code>.</td></tr>
<tr valign="top"><td><code>nodes</code></td>
<td>
Should the terminal node indicators (an n by ntree
matrix) be return? If so, it is in the ``nodes'' attribute of the
returned object.</td></tr>
<tr valign="top"><td><code>cutoff</code></td>
<td>
(Classification only) A vector of length equal to
number of classes. The `winning' class for an observation is the
one with the maximum ratio of proportion of votes to cutoff.
Default is taken from the <code>forest$cutoff</code> component of
<code>object</code> (i.e., the setting used when running
<code><a href="randomForest.html">randomForest</a></code>).</td></tr>
<tr valign="top"><td><code>...</code></td>
<td>
not used currently.</td></tr>
</table>
<h3>Value</h3>
<p>
If <code>object$type</code> is <code>regression</code>, a vector of predicted
values is returned. If <code>predict.all=TRUE</code>, then the returned
object is a list of two components: <code>aggregate</code>, which is the
vector of predicted values by the forest, and <code>individual</code>, which
is a matrix where each column contains prediction by a tree in the
forest.
<br>
If <code>object$type</code> is <code>classification</code>, the object returned
depends on the argument <code>type</code>:
</p>
<table summary="R argblock">
<tr valign="top"><td><code>response</code></td>
<td>
predicted classes (the classes with majority vote).</td></tr>
<tr valign="top"><td><code>prob</code></td>
<td>
matrix of class probabilities (one column for each class
and one row for each input).</td></tr>
<tr valign="top"><td><code>vote</code></td>
<td>
matrix of vote counts (one column for each class
and one row for each new input); either in raw counts or in fractions
(if <code>norm.votes=TRUE</code>).</td></tr>
</table>
<p>
<br>
If <code>predict.all=TRUE</code>, then the <code>individual</code> component of the
returned object is a character matrix where each column contains the
predicted class by a tree in the forest.
<br>
If <code>proximity=TRUE</code>, the returned object is a list with two
components: <code>pred</code> is the prediction (as described above) and
<code>proximity</code> is the proximitry matrix. An error is issued if
<code>object$type</code> is <code>regression</code>.
<br>
If <code>nodes=TRUE</code>, 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.</p>
<h3>Author(s)</h3>
<p>
Andy Liaw <a href="mailto:andy_liaw@merck.com">andy_liaw@merck.com</a> and Matthew Wiener
<a href="mailto:matthew_wiener@merck.com">matthew_wiener@merck.com</a>, based on original Fortran code by
Leo Breiman and Adele Cutler.
</p>
<h3>References</h3>
<p>
Breiman, L. (2001), <EM>Random Forests</EM>, Machine Learning 45(1),
5-32.
</p>
<h3>See Also</h3>
<p>
<code><a href="randomForest.html">randomForest</a></code>
</p>
<h3>Examples</h3>
<pre>
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)
</pre>
<hr><div align="center">[Package <em>randomForest</em> version 4.5-27 <a href="00Index.html">Index]</a></div>
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -