UnsupervisedEstimator

Trait UnsupervisedEstimator 

Source
pub trait UnsupervisedEstimator {
    type Labels;

    // Required methods
    fn fit(&mut self, x: &Matrix<f32>) -> Result<()>;
    fn predict(&self, x: &Matrix<f32>) -> Self::Labels;
}
Expand description

Trait for unsupervised learning models.

§Examples

use aprender::prelude::*;

// Create data with 2 clear clusters
let data = Matrix::from_vec(6, 2, vec![
    0.0, 0.0, 0.1, 0.1, 0.2, 0.0,  // Cluster 1
    10.0, 10.0, 10.1, 10.1, 10.0, 10.2,  // Cluster 2
]).unwrap();

let mut kmeans = KMeans::new(2).with_random_state(42);
kmeans.fit(&data).unwrap();
let labels = kmeans.predict(&data);
assert_eq!(labels.len(), 6);

Required Associated Types§

Source

type Labels

The type of labels/clusters produced.

Required Methods§

Source

fn fit(&mut self, x: &Matrix<f32>) -> Result<()>

Fits the model to data.

§Errors

Returns an error if fitting fails (empty data, invalid parameters, etc.).

Source

fn predict(&self, x: &Matrix<f32>) -> Self::Labels

Predicts cluster assignments or transforms data.

Implementors§