brute_force_knn  R Documentation 
Returns the exact nearest neighbors of a dataset. A brute force search is carried out: all possible pairs of points are compared, and the nearest neighbors are returned.
brute_force_knn(
data,
k,
metric = "euclidean",
use_alt_metric = TRUE,
n_threads = 0,
verbose = FALSE,
obs = "R"
)
data 
Matrix of 
k 
Number of nearest neighbors to return. 
metric 
Type of distance calculation to use. One of:
For nonsparse data, the following variants are available with preprocessing: this trades memory for a potential speed up during the distance calculation. Some minor numerical differences should be expected compared to the nonpreprocessed versions:
For nonsparse binary data passed as a

use_alt_metric 
If 
n_threads 
Number of threads to use. 
verbose 
If 
obs 
set to 
This method is accurate but scales poorly with dataset size, so use with caution with larger datasets. Having the exact neighbors as a ground truth to compare with approximate results is useful for benchmarking and determining parameter settings of the approximate methods.
the nearest neighbor graph as a list containing:
idx
an n by k matrix containing the nearest neighbor indices.
dist
an n by k matrix containing the nearest neighbor distances.
# Find the 4 nearest neighbors using Euclidean distance
# If you pass a data frame, nonnumeric columns are removed
iris_nn < brute_force_knn(iris, k = 4, metric = "euclidean")
# Manhattan (l1) distance
iris_nn < brute_force_knn(iris, k = 4, metric = "manhattan")
# Multithreading: you can choose the number of threads to use: in real
# usage, you will want to set n_threads to at least 2
iris_nn < brute_force_knn(iris, k = 4, metric = "manhattan", n_threads = 1)
# Use verbose flag to see information about progress
iris_nn < brute_force_knn(iris, k = 4, metric = "euclidean", verbose = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.