k-Nearest-Neighbors Search

>>> from mlpack import knn

This program will calculate the k-nearest-neighbors of a set of points using kd-trees or cover trees (cover tree support is experimental and may be slow). You may specify a separate set of reference points and query points, or just a reference set which will be used as both the reference and query set.

For example, the following command will calculate the 5 nearest neighbors of each point in 'input' and store the distances in 'distances' and the neighbors in 'neighbors':

>>> knn(k=5, reference=input)
>>> neighbors = output['neighbors']

The output files are organized such that row i and column j in the neighbors output matrix corresponds to the index of the point in the reference set which is the j'th nearest neighbor from the point in the query set with index i. Row j and column i in the distances output matrix corresponds to the distance between those two points.

input options

output options

The return value from the binding is a dict containing the following elements: