/// Init a list of neighbors for a specified test object x, and given
/// training data.
///
/// # Arguments
/// * `x` - Test object.
/// * `train_x` - Training objects.
/// * `train_y` - Training labels.
/// * `max_k` - Maximum number of neighbors to store for test object x.
///
Init a list of neighbors for a specified test object x, and given
training data.
Init a list of neighbors for a specified test object x and given training data .
fn from_data(
        x: &ArrayView1<f64>,
        train_x: &ArrayView2<f64>,
        train_y: &ArrayView1<Label>,
        max_k: usize,
        distance: D,
    ) -> NearestNeighbors<D> {
        assert!(max_k > 0);
        let mut knn = NearestNeighbors::new(x, max_k, distance);
        for (xi, yi) in train_x.outer_iter().zip(train_y) {
            // NOTE: we use std::usize::MAX as a bogus label to split ties in
            // predict(); if this becomes a problem, predict() needs to be
            // fixed as well.
            assert!(
                *yi != std::usize::MAX,
                "label {} is too large and currently not supported",
                *yi
            );
            knn.add_example(&xi, *yi);
        }
        knn
    }
fn from_data ( x : & ArrayView1 < f64 > , train_x : & ArrayView2 < f64 > , train_y : & ArrayView1 < Label > , max_k : usize , distance : D , ) -> NearestNeighbors < D > { assert ! ( max_k 0 ) ; let mut knn = NearestNeighbors :: new ( x , max_k , distance ) ; for ( xi , yi ) in train_x . outer_iter ( ) . zip ( train_y ) { // NOTE: we use std::usize::MAX as a bogus label to split ties in // predict(); if this becomes a problem, predict() needs to be // fixed as well. assert ! ( yi std usize MAX " " yi ) ; knn . add_example ( & xi , * yi ) ; } knn }
Init a list of neighbors for a specified test object x, and given
training data.
Init a list of neighbors for a specified test object x and given training data .
x
&ArrayView1<f64>
train_x
&ArrayView2<f64>
train_y
&ArrayView1<Label>
max_k
usize
distance
D