getknn | R Documentation |
Function getknn
selects the k
nearest neighbours of each row observation of a new (= test) data set within a reference (= training) data set, based on a dissimilarity measure.
getknn
uses function get.knnx
of package FNN
(Beygelzimer et al.) available on CRAN.
getknn(Xr, Xu, k = NULL,
diss = c("euclidean", "mahalanobis", "correlation"),
algorithm = "brute", list = TRUE)
Xr |
A |
Xu |
A |
k |
The number of nearest neighbors to select. |
diss |
The type of dissimilarity used between observations. Possible values are "euclidean" (default; Euclidean distance), "mahalanobis" (Mahalanobis distance), or "correlation". Correlation dissimilarities are calculated by |
algorithm |
Search algorithm used for Euclidean and Mahalanobis distances. Default to |
list |
If |
A list of outputs, such as:
nn |
A |
d |
A |
listnn |
Same as |
listd |
Same as |
data(datcass)
Xr <- datcass$Xr
Xu <- datcass$Xu
k <- 5
getknn(Xr, Xu[1:3, ], k = k)
z <- pca(Xr, Xu, ncomp = 15)
Tr <- z$Tr
Tu <- z$Tu[1:10, ]
k <- 5
getknn(Tr, Tu, k = k, diss = "mahalanobis")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.