The k-nearest neighbours using the cosinus distance | R Documentation |
The k-nearest neighbours using the cosinus distance.
cosnn(xnew, x, k = 5, index = FALSE, rann = FALSE)
xnew |
The new data whose k-nearest neighbours are to be found. |
x |
The data, a numeric matrix with unit vectors. |
k |
The number of nearest neighbours, set to 5 by default. It can also be a vector with many values. |
index |
If you want the indices of the closest observations set this equal to TRUE. |
rann |
If you have large scale datasets and want a faster k-NN search, you can use kd-trees implemented in the R package "RANN". In this case you must set this argument equal to TRUE. |
The shortest distances or the indices of the k-nearest neighbours using the cosinus distance are returned.
A matrix with the shortest distance of each xnew from x, if index is FALSE, or the indices of the nearest neighbours of each xnew from x, if index is TRUE.
Michail Tsagris.
R implementation and documentation: Michail Tsagris mtsagris@uoc.gr.
Tsagris M. and Alenazi A. (2019). Comparison of discriminant analysis methods on the sphere. Communications in Statistics: Case Studies, Data Analysis and Applications, 5(4): 467–491.
dirknn, dirknn.tune
xnew <- rvmf(10, rnorm(3), 5)
x <- rvmf(50, rnorm(3), 5)
a <- cosnn(xnew, x, k = 5)
b <- cosnn(xnew, x, k = 5, index = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.