[][src]Trait opencv::ml::prelude::KNearest

pub trait KNearest: StatModel {
    pub fn as_raw_KNearest(&self) -> *const c_void;
pub fn as_raw_mut_KNearest(&mut self) -> *mut c_void; pub fn get_default_k(&self) -> Result<i32> { ... }
pub fn set_default_k(&mut self, val: i32) -> Result<()> { ... }
pub fn get_is_classifier(&self) -> Result<bool> { ... }
pub fn set_is_classifier(&mut self, val: bool) -> Result<()> { ... }
pub fn get_emax(&self) -> Result<i32> { ... }
pub fn set_emax(&mut self, val: i32) -> Result<()> { ... }
pub fn get_algorithm_type(&self) -> Result<i32> { ... }
pub fn set_algorithm_type(&mut self, val: i32) -> Result<()> { ... }
pub fn find_nearest(
        &self,
        samples: &dyn ToInputArray,
        k: i32,
        results: &mut dyn ToOutputArray,
        neighbor_responses: &mut dyn ToOutputArray,
        dist: &mut dyn ToOutputArray
    ) -> Result<f32> { ... } }

The class implements K-Nearest Neighbors model

See also

@ref ml_intro_knn

Required methods

Loading content...

Provided methods

pub fn get_default_k(&self) -> Result<i32>[src]

Default number of neighbors to use in predict method.

See also

setDefaultK

pub fn set_default_k(&mut self, val: i32) -> Result<()>[src]

Default number of neighbors to use in predict method.

See also

setDefaultK getDefaultK

pub fn get_is_classifier(&self) -> Result<bool>[src]

Whether classification or regression model should be trained.

See also

setIsClassifier

pub fn set_is_classifier(&mut self, val: bool) -> Result<()>[src]

Whether classification or regression model should be trained.

See also

setIsClassifier getIsClassifier

pub fn get_emax(&self) -> Result<i32>[src]

Parameter for KDTree implementation.

See also

setEmax

pub fn set_emax(&mut self, val: i32) -> Result<()>[src]

Parameter for KDTree implementation.

See also

setEmax getEmax

pub fn get_algorithm_type(&self) -> Result<i32>[src]

%Algorithm type, one of KNearest::Types.

See also

setAlgorithmType

pub fn set_algorithm_type(&mut self, val: i32) -> Result<()>[src]

%Algorithm type, one of KNearest::Types.

See also

setAlgorithmType getAlgorithmType

pub fn find_nearest(
    &self,
    samples: &dyn ToInputArray,
    k: i32,
    results: &mut dyn ToOutputArray,
    neighbor_responses: &mut dyn ToOutputArray,
    dist: &mut dyn ToOutputArray
) -> Result<f32>
[src]

Finds the neighbors and predicts responses for input vectors.

Parameters

  • samples: Input samples stored by rows. It is a single-precision floating-point matrix of <number_of_samples> * k size.
  • k: Number of used nearest neighbors. Should be greater than 1.
  • results: Vector with results of prediction (regression or classification) for each input sample. It is a single-precision floating-point vector with <number_of_samples> elements.
  • neighborResponses: Optional output values for corresponding neighbors. It is a single- precision floating-point matrix of <number_of_samples> * k size.
  • dist: Optional output distances from the input vectors to the corresponding neighbors. It is a single-precision floating-point matrix of <number_of_samples> * k size.

For each input vector (a row of the matrix samples), the method finds the k nearest neighbors. In case of regression, the predicted result is a mean value of the particular vector's neighbor responses. In case of classification, the class is determined by voting.

For each input vector, the neighbors are sorted by their distances to the vector.

In case of C++ interface you can use output pointers to empty matrices and the function will allocate memory itself.

If only a single input vector is passed, all output matrices are optional and the predicted value is returned by the method.

The function is parallelized with the TBB library.

C++ default parameters

  • neighbor_responses: noArray()
  • dist: noArray()
Loading content...

Implementations

impl<'_> dyn KNearest + '_[src]

pub fn create() -> Result<Ptr<dyn KNearest>>[src]

Creates the empty model

The static method creates empty %KNearest classifier. It should be then trained using StatModel::train method.

pub fn load(filepath: &str) -> Result<Ptr<dyn KNearest>>[src]

Loads and creates a serialized knearest from a file

Use KNearest::save to serialize and store an KNearest to disk. Load the KNearest from this file again, by calling this function with the path to the file.

Parameters

  • filepath: path to serialized KNearest

Implementors

impl KNearest for PtrOfKNearest[src]

Loading content...