Struct rusty_machine::learning::k_means::KMeansClassifier
source · [−]pub struct KMeansClassifier<InitAlg: Initializer> { /* private fields */ }
Expand description
K-Means Classification model.
Contains option for centroids. Specifies iterations and number of classes.
Usage
This model is used through the UnSupModel
trait. The model is
trained via the train
function with a matrix containing rows of
feature vectors.
The model will not check to ensure the data coming in is all valid. This responsibility lies with the user (for now).
Implementations
sourceimpl KMeansClassifier<KPlusPlus>
impl KMeansClassifier<KPlusPlus>
sourcepub fn new(k: usize) -> KMeansClassifier<KPlusPlus>
pub fn new(k: usize) -> KMeansClassifier<KPlusPlus>
Constructs untrained k-means classifier model.
Requires number of classes to be specified. Defaults to 100 iterations and kmeans++ initialization.
Examples
use rusty_machine::learning::k_means::KMeansClassifier;
let model = KMeansClassifier::new(5);
sourceimpl<InitAlg: Initializer> KMeansClassifier<InitAlg>
impl<InitAlg: Initializer> KMeansClassifier<InitAlg>
sourcepub fn new_specified(
k: usize,
iters: usize,
algo: InitAlg
) -> KMeansClassifier<InitAlg>
pub fn new_specified(
k: usize,
iters: usize,
algo: InitAlg
) -> KMeansClassifier<InitAlg>
Constructs untrained k-means classifier model.
Requires number of classes, number of iterations, and the initialization algorithm to use.
Examples
use rusty_machine::learning::k_means::{KMeansClassifier, Forgy};
let model = KMeansClassifier::new_specified(5, 42, Forgy);
sourcepub fn init_algorithm(&self) -> &InitAlg
pub fn init_algorithm(&self) -> &InitAlg
Get the initialization algorithm.
Trait Implementations
sourceimpl<InitAlg: Debug + Initializer> Debug for KMeansClassifier<InitAlg>
impl<InitAlg: Debug + Initializer> Debug for KMeansClassifier<InitAlg>
sourceimpl<InitAlg: Initializer> UnSupModel<Matrix<f64>, Vector<usize>> for KMeansClassifier<InitAlg>
impl<InitAlg: Initializer> UnSupModel<Matrix<f64>, Vector<usize>> for KMeansClassifier<InitAlg>
sourcefn predict(&self, inputs: &Matrix<f64>) -> LearningResult<Vector<usize>>
fn predict(&self, inputs: &Matrix<f64>) -> LearningResult<Vector<usize>>
Predict classes from data.
Model must be trained.
sourcefn train(&mut self, inputs: &Matrix<f64>) -> LearningResult<()>
fn train(&mut self, inputs: &Matrix<f64>) -> LearningResult<()>
Train the classifier using input data.