Description Usage Arguments Details Value Author(s) Examples
Fast k-Nearest Neighbor classifier build upon ANN, a high efficient
C++
library for nearest neighbor searching.
1 |
xtr |
matrix containing the training instances. Rows are observations and columns are variables. Only numeric variables are allowed. |
ytr |
factor array with the training labels. |
xte |
matrix containing the test instances. |
k |
number of neighbors considered. |
method |
method used to infer the class membership probabilities of the
test instances. Choose |
normalize |
variable normalization to be applied prior to searching the
nearest neighbors. Default is
|
There are two estimators for the class membership probabilities:
method="vote"
: The classical estimator based on the label
proportions of the nearest neighbors. This estimator can be thought as of a
voting rule.
method="dist"
: A shrinkage estimator based on the distances
from the nearest neighbors, so that those neighbors more close to the test
observation have more importance on predicting the class label. This
estimator can be thought as of a weighted voting rule. In general,
it reduces log-loss.
list
with predictions for the test set:
class
: factor array of predicted classes.
prob
: matrix with predicted probabilities.
David Pinto.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | ## Not run:
library("mlbench")
library("caTools")
library("fastknn")
data("Ionosphere")
x <- data.matrix(subset(Ionosphere, select = -Class))
y <- Ionosphere$Class
set.seed(2048)
tr.idx <- which(sample.split(Y = y, SplitRatio = 0.7))
x.tr <- x[tr.idx,]
x.te <- x[-tr.idx,]
y.tr <- y[tr.idx]
y.te <- y[-tr.idx]
knn.out <- fastknn(xtr = x.tr, ytr = y.tr, xte = x.te, k = 10)
knn.out$class
knn.out$prob
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.