Expand description
  • k-Nearest Nerighbors

Contains implemention of k-nearest search using kd-tree, ball-tree and brute-force.

Usage

use rusty_machine::learning::knn::KNNClassifier;
use rusty_machine::learning::SupModel;
use rusty_machine::linalg::Vector;

let data = matrix![1., 1., 1.;
                   1., 2., 3.;
                   2., 3., 1.;
                   2., 2., 0.];
let target = Vector::new(vec![0, 0, 1, 1]);

// train the model to search 2-nearest
let mut knn = KNNClassifier::new(2);
knn.train(&data, &target).unwrap();

// predict new points
let res = knn.predict(&matrix![2., 3., 0.; 1., 1., 2.]).unwrap();
assert_eq!(res, Vector::new(vec![1, 0]));

Structs

Perform brute-force search
k-Nearest Neighbor Classifier

Traits

Search K-nearest items

Type Definitions

Ball-tree implementation
Kd-tree implementation