📄 knn.var.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>R: K-Nearest Neighbor Classification With Variable Selection</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 knn.var {knnTree}"><tr><td>knn.var {knnTree}</td><td align="right">R Documentation</td></tr></table>
<h2>K-Nearest Neighbor Classification With Variable Selection</h2>
<h3>Description</h3>
<p>
Construct or predict with k-nearest-neighbor classifiers,
using cross-validation to select variables by forward or backward selection,
to choose the best k and to choose scaling methods.
</p>
<h3>Usage</h3>
<pre>knn.var (train, test, k.vec = seq (1, 31, by=2),
theyre.the.same=FALSE,
return.all.rates=FALSE, scaling = 1, backward = FALSE, max.steps=-1,
save.call = FALSE,
verbose = 0, use.big=TRUE)</pre>
<h3>Arguments</h3>
<table summary="R argblock">
<tr valign="top"><td><code>train</code></td>
<td>
</td></tr>
<tr valign="top"><td><code>test</code></td>
<td>
</td></tr>
<tr valign="top"><td><code>k.vec</code></td>
<td>
</td></tr>
<tr valign="top"><td><code>theyre.the.same</code></td>
<td>
</td></tr>
<tr valign="top"><td><code>return.all.rates</code></td>
<td>
</td></tr>
<tr valign="top"><td><code>scaling</code></td>
<td>
</td></tr>
<tr valign="top"><td><code>backward</code></td>
<td>
</td></tr>
<tr valign="top"><td><code>max.steps</code></td>
<td>
</td></tr>
<tr valign="top"><td><code>save.call</code></td>
<td>
</td></tr>
<tr valign="top"><td><code>verbose</code></td>
<td>
</td></tr>
<tr valign="top"><td><code>use.big</code></td>
<td>
</td></tr>
</table>
<p>
{logical, TRUE if the C code should try to use a
technique that uses more memory but runs faster.}</p>
<h3>Details</h3>
<p>
<font face="Courier New,Courier" color="#666666"><b>R</b></font>{knn.var} constructs a k-nearest-neighbor classifier using
Euclidean metric. Leave-one-out cross-validation together with stepwise (forward
or backward, but not both) selection is used to find the best set of variables to
include, the best choice of k, and whether the data should be scaled.
</p>
<h3>Value</h3>
<p>
Object of class knn. This is a list with between six and eight
of the following components:<br>
which: logical vector, one per input variable; the i-th element of which is TRUE if the i-th input variable is in the classifier<br>
rate: Smallest misclassification rate acheived by algorithm. If
return.all.rates is TRUE this is a vector of error rates, one for each element
of k.vec<br>
best.k: Number giving the optimal value of k, chosen from among the elements
of k.vec.<br>
scaled: indicator of best scaling. FALSE means no scaling was used; TRUE
means scaling was used. <br>
n: the number of observations in the training set<br>
col.sds: Numeric vector of scaling factors, present only if scaled != 0.
If scaled = 1 these are column SD's; if scaled = 2 they are MAD's.<br>
pure: logical, TRUE if every item in the training set had the same class. If
a training set is pure then all the elements of which are FALSE, best.k is
taken to be the first element of k.vec and scaled is set to 0.<br>
call: a copy of the call used to create the object, if save.call was TRUE</p>
<h3>Author(s)</h3>
<p>
Sam Buttrey <a href="mailto:buttrey@nps.navy.mil">buttrey@nps.navy.mil</a>
</p>
<h3>References</h3>
<p>
Buttrey and Karo, 2002
</p>
<h3>See Also</h3>
<p>
<code><a href="knnTree.html">knnTree</a></code>
</p>
<h3>Examples</h3>
<pre>
data(iris)
set.seed (3)
samp <- sample (nrow(iris), size = 75, replace=FALSE)
knn.var (iris[samp,c(5, 1:4)]) # Build classifier
# Output produced by this-is-escaped-codenormal-bracket33bracket-normal
## Not run: This knn classifier is based on 75 observations.
It uses 1 out of 4 variables without scaling.
Training rate is 0.01333 , achieved at k = 1## End(Not run)
iris.knn <- knn.var (iris[samp,c(5, 1:4)]) # Build and save, then predict
predict (iris.knn, iris[-samp,c(5, 1:4)], iris[samp, c(5, 1:4)])
## Not run:
$rate
[1] 0.08
## End(Not run)
</pre>
<hr><div align="center">[Package <em>knnTree</em> version 1.2.4 <a href="00Index.html">Index]</a></div>
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -