Module k_means

Module k_means 

Source
Expand description

K-means Classification

Provides implementation of K-Means classification.

§Usage

use rusty_machine::linalg::Matrix;
use rusty_machine::learning::k_means::KMeansClassifier;
use rusty_machine::learning::UnSupModel;

let inputs = Matrix::new(3, 2, vec![1.0, 2.0, 1.0, 3.0, 1.0, 4.0]);
let test_inputs = Matrix::new(1, 2, vec![1.0, 3.5]);

// Create model with k(=2) classes.
let mut model = KMeansClassifier::new(2);

// Where inputs is a Matrix with features in columns.
model.train(&inputs).unwrap();

// Where test_inputs is a Matrix with features in columns.
let a = model.predict(&test_inputs).unwrap();

Additionally you can control the initialization algorithm and max number of iterations.

§Initializations

Three initialization algorithms are supported.

§Forgy initialization

Choose initial centroids randomly from the data.

§Random Partition initialization

Randomly assign each data point to one of k clusters. The initial centroids are the mean of the data in their class.

§K-means++ initialization

The k-means++ scheme.

Structs§

Forgy
The Forgy initialization scheme.
KMeansClassifier
K-Means Classification model.
KPlusPlus
The K-means ++ initialization scheme.
RandomPartition
The Random Partition initialization scheme.

Traits§

Initializer
Trait for algorithms initializing the K-means centroids.