Skip to content

kMeansCluster

kMeansCluster(points, numCluster, randomSource?): object

Defined in: src/k_means_cluster.js:17

Perform k-means clustering.

number[][]

N-dimensional coordinates of points to be clustered.

number

How many clusters to create.

Function = Math.random

An optional entropy source that generates uniform values in [0, 1).

object

Labels (same length as data) and centroids (same length as numCluster).

centroids: number[][]

labels: number[]

If any centroids wind up friendless (i.e., without associated points).

kMeansCluster([[0.0, 0.5], [1.0, 0.5]], 2); // => {labels: [0, 1], centroids: [[0.0, 0.5], [1.0, 0.5]]}