K Means#
A fast online centroid-based hard clustering algorithm capable of grouping linearly separable data points given some prior knowledge of the target number of clusters (defined by k). K Means is trained using adaptive Mini Batch Gradient Descent and minimizes the inertia cost function at each epoch. Inertia is defined as the average sum of distances between each sample and its nearest cluster centroid.
Interfaces: Estimator, Learner, Online, Probabilistic, Persistable, Verbose
Data Type Compatibility: Continuous
Parameters#
| # | Name | Default | Type | Description |
|---|---|---|---|---|
| 1 | k | int | The number of target clusters. | |
| 2 | batchSize | 128 | int | The size of each mini batch in samples. |
| 3 | epochs | 300 | int | The maximum number of training rounds to execute. |
| 4 | minChange | 1e-4 | float | The minimum change in the inertia for training to continue. |
| 5 | kernel | Euclidean | Distance | The distance kernel used to compute the distance between sample points. |
| 6 | seeder | PlusPlus | Seeder | The seeder used to initialize the cluster centroids. |
Example#
use Rubix\ML\Clusterers\KMeans;
use Rubix\ML\Kernels\Distance\Euclidean;
use Rubix\ML\Clusterers\Seeders\PlusPlus;
$estimator = new KMeans(3, 128, 300, 10.0, new Euclidean(), new PlusPlus());
Additional Methods#
Return the k computed centroids of the training set.
public centroids() : array[]
Return the number of training samples that each centroid is responsible for.
public sizes() : int[]
Return the loss for each epoch from the last training session.
public losses() : float[]|null
Return the progress table combining every epoch recorded during the last training session — the inertia at each epoch — into a single ordered sequence.
public progress() : iterable
References#
-
D. Sculley. (2010). Web-Scale K-Means Clustering. ↩