# Struct cogset::Kmeans
[-] [+]
[src]

pub struct Kmeans<T> { // some fields omitted }

Clustering via the *k*-means algorithm (aka Lloyd's algorithm).

k-means clustering aims to partitionnobservations intokclusters in which each observation belongs to the cluster with the nearest mean, serving as a prototype of the cluster.^{wikipedia}

This is a heuristic, iterative approximation to the true optimal
assignment. The parameters used to control the approximation can
be set via `KmeansBuilder`

.

# Examples

use cogset::{Euclid, Kmeans}; let data = [Euclid([0.0, 0.0]), Euclid([1.0, 0.5]), Euclid([0.2, 0.2]), Euclid([0.3, 0.8]), Euclid([0.0, 1.0])]; let k = 3; let kmeans = Kmeans::new(&data, k); println!("{:?}", kmeans.clusters());

## Methods

`impl<T> Kmeans<T> where Euclid<T>: Point + Euclidean + Clone`

`fn new(data: &[Euclid<T>], k: usize) -> Kmeans<T>`

Run k-means on `data`

with the default settings.

`fn clusters(&self) -> Vec<(Euclid<T>, Vec<usize>)>`

Retrieve the means and the clusters themselves that this
*k*-means instance computed.

The clusters are represented by vectors of indexes into the original data.

`fn converged(&self) -> Result<usize, usize>`

Return whether the algorithm converged, and how many steps that took.

`Ok`

is returned if the algorithm did meet the tolerance
criterion, and `Err`

if it reached the iteration limit
instead.