distMat.knn.index.dist {KernelKnn} | R Documentation |
indices and distances of k-nearest-neighbors using a distance matrix
Description
indices and distances of k-nearest-neighbors using a distance matrix
Usage
distMat.knn.index.dist(
DIST_mat,
TEST_indices = NULL,
k = 5,
threads = 1,
minimize = T
)
Arguments
DIST_mat |
a distance matrix (square matrix) having a diagonal filled with either zero's (0) or NA's (missing values) |
TEST_indices |
a numeric vector specifying the indices of the test data in the distance matrix (row-wise or column-wise). If the parameter equals NULL then no test data is included in the distance matrix |
k |
an integer specifying the k-nearest-neighbors |
threads |
the number of cores to be used in parallel (openmp will be employed) |
minimize |
either TRUE or FALSE. If TRUE then lower values will be considered as relevant for the k-nearest search, otherwise higher values. |
Details
This function takes a number of arguments and it returns the indices and distances of the k-nearest-neighbors for each observation. If TEST_indices is NULL then the indices-distances for the DIST_mat be returned, whereas if TEST_indices is not NULL then the indices-distances for the test data only will be returned.
Value
a list of length 2. The first sublist returns the indices and the second the distances of the k nearest neighbors for each observation. If TEST_indices is NULL the number of rows of each sublist equals the number of rows in the DIST_mat data. If TEST_indices is not NULL the number of rows of each sublist equals the length of the input TEST_indices.
Author(s)
Lampros Mouselimis
Examples
data(Boston)
X = Boston[, -ncol(Boston)]
dist_obj = dist(X)
dist_mat = as.matrix(dist_obj)
out = distMat.knn.index.dist(dist_mat, TEST_indices = NULL, k = 5)