Skip to main content

KNearestNeighbours

Struct KNearestNeighbours 

Source
pub struct KNearestNeighbours { /* private fields */ }
Expand description

k-nearest-neighbours classifier.

Implementations§

Source§

impl KNearestNeighbours

Source

pub fn new() -> Result<Self>

Build a new k-NN classifier in f64 precision. The number of neighbours k defaults to AOCL-DA’s built-in default (commonly 5); call KNearestNeighbours::handle_mut and set_int_option to override it (the option name is AOCL-version specific — try "number of neighbours").

Source

pub fn handle_mut(&mut self) -> &mut Handle

Borrow the underlying handle to set algorithm-specific options.

Source

pub fn fit( &mut self, n_samples: usize, n_features: usize, x_train: &[f64], y_train: &[i32], ) -> Result<()>

Fit with n_samples × n_features training data (column-major) and a n_samples integer label vector.

Source

pub fn predict( &mut self, n_queries: usize, n_features: usize, x_test: &[f64], labels: &mut [i32], ) -> Result<()>

Predict labels for n_queries × n_features samples (column-major).

Source

pub fn kneighbors( &mut self, n_queries: usize, n_features: usize, x_test: &[f64], n_ind: &mut [i32], n_dist: &mut [f64], k: usize, return_distance: bool, ) -> Result<()>

For each of n_queries test rows, write into n_ind (length n_queries · k) the column-major indices of its k nearest training-set neighbours. If return_distance is true, also fill n_dist (same shape) with the distances.

Source

pub fn classes(&self, classes: &mut [i32]) -> Result<usize>

Retrieve the unique class labels seen during training, ascending, into classes (at most classes.len() of them). Returns the number of classes, which may exceed classes.len().

Source

pub fn predict_proba( &mut self, n_queries: usize, n_features: usize, x_test: &[f64], proba: &mut [f64], ) -> Result<()>

Probability estimates: n_queries × n_classes column-major matrix at proba (element (query, class) at class * n_queries + query). Use KNearestNeighbours::classes to discover which class each column corresponds to.

Trait Implementations§

Source§

impl Debug for KNearestNeighbours

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.