mlpack_knn(1)

πŸ’– mlpack_knn β€” the k-nearest-neighbors search page, bestie edition πŸ’–

okay so. welcome to mlpack_knn(1), a User Commands manual page, and yes this is the one where you find everyone's nearest neighbors. it's giving "who's in your circle" but make it math. let's GO ✨


🌸 NAME 🌸

mlpack_knn β€” k-nearest-neighbors search. that's it. that's the whole name. iconic.


πŸŽ€ SYNOPSIS πŸŽ€

mlpack_knn [-a string] [-e double] [-m unknown] [-k int] [-l int] [-q unknown] [-R bool] [-r unknown] [-b double] [-s int] [-u double] [-t string] [-D unknown] [-T unknown] [-V bool] [-d unknown] [-n unknown] [-M unknown] [-h -v]

like. look at all those little flags. they're all yours and they're all optional. we love a flexible queen πŸ’…


✨ DESCRIPTION ✨

so what this program does: it calculates the k-nearest-neighbors of a set of points, using either kd-trees or cover trees. heads up though β€” cover tree support is experimental and may be slow, so don't come for me if it chugs. 🐌

you've got options for how you feed it data, and they're both cute:

  • you can specify a separate set of reference points and query points, or
  • you can just hand it a reference set, and it'll be used as both the reference and the query set. two jobs, one file, main character energy.

for example β€” and this is the part where you screenshot it, fr fr β€” the following command will calculate the 5 nearest neighbors of each point in input.csv and store the distances in distances.csv and the neighbors in neighbors.csv:

$ mlpack_knn --k 5 --reference_file input.csv --neighbors_file neighbors.csv --distances_file distances.csv

now, the output layout. this matters, don't skip it πŸ™ˆ

The output is 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.

(read that twice. it's the vibe check of this whole page.) πŸ¦‹


πŸ’… OPTIONAL INPUT OPTIONS πŸ’…

these are the optional ones, meaning you could skip them, but why would you skip anything, bestie. girl dinner of flags:

  • --algorithm (-a) [string] β€” Type of neighbor search: 'naive', 'single_tree', 'dual_tree', 'greedy'. Default value 'dual_tree'.
  • --epsilon (-e) [double] β€” If specified, will do approximate nearest neighbor search with given relative error. Default value 0.
  • --help (-h) [bool] β€” Default help info.
  • --info [string] β€” Print help on a specific option. Default value ''.
  • --input_model_file (-m) [unknown] β€” Pre-trained kNN model.
  • --k (-k) [int] β€” Number of nearest neighbors to find. Default value 0.
  • --leaf_size (-l) [int] β€” Leaf size for tree building (used for kd-trees, vp trees, random projection trees, UB trees, R trees, R* trees, X trees, Hilbert R trees, R+ trees, R++ trees, spill trees, and octrees). Default value 20.
  • --query_file (-q) [unknown] β€” Matrix containing query points (optional).
  • --random_basis (-R) [bool] β€” Before tree-building, project the data onto a random orthogonal basis.
  • --reference_file (-r) [unknown] β€” Matrix containing the reference dataset.
  • --rho (-b) [double] β€” Balance threshold (only valid for spill trees). Default value 0.7.
  • --seed (-s) [int] β€” Random seed (if 0, std::time(NULL) is used). Default value 0.
  • --tau (-u) [double] β€” Overlapping size (only valid for spill trees). Default value 0.
  • --tree_type (-t) [string] β€” Type of tree to use: 'kd', 'vp', 'rp', 'max-rp', 'ub', 'cover', 'r', 'r-star', 'x', 'ball', 'hilbert-r', 'r-plus', 'r-plus-plus', 'spill', 'oct'. Default value 'kd'.
  • --true_distances_file (-D) [unknown] β€” Matrix of true distances to compute the effective error (average relative error) (it is printed when -v is specified).
  • --true_neighbors_file (-T) [unknown] β€” Matrix of true neighbors to compute the recall (it is printed when -v is specified).
  • --verbose (-v) [bool] β€” Display informational messages and the full list of parameters and timers at the end of execution.
  • --version (-V) [bool] β€” Display the version of mlpack.

like, fifteen tree types, bestie. that's not a menu, that's a whole restaurant. πŸ“


🧚 OPTIONAL OUTPUT OPTIONS 🧚

where your results go to be fabulous:

  • --distances_file (-d) [unknown] β€” Matrix to output distances into.
  • --neighbors_file (-n) [unknown] β€” Matrix to output neighbors into.
  • --output_model_file (-M) [unknown] β€” If specified, the kNN model will be output here.

🌈 ADDITIONAL INFORMATION 🌈

For further information, including relevant papers, citations, and theory, consult the documentation found at http://www.mlpack.org or included with your distribution of mlpack.

(translation: the docs are right there, go read them, they're actually kind of great πŸ’œ)


and that's the page!! slay, periodt, no cap πŸ‘‘ this whole thing is mlpack-4.8.0, dated 22 June 2026, and it lives in the mlpack_knn(1) era of your life. go find your neighbors bestie, they're closer than you think πŸ’–βœ¨πŸ«Ά

πŸ“¦ where this page comes from