View source: R/dist_knn_index_dist.R
distMat.knn.index.dist | R Documentation |
indices and distances of k-nearest-neighbors using a distance matrix
distMat.knn.index.dist( DIST_mat, TEST_indices = NULL, k = 5, threads = 1, minimize = T )
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. |
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.
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.
Lampros Mouselimis
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.