lambda-ml.clustering.k-means

K-means clustering.

Example usage:

(def data [[1 1] [1.5 2] [3 4] [5 7] [3.5 5] [4.5 5] [3.5 4.5]])
(let [k 2]
  (-> (k-means k lambda-ml.distance/euclidean data)
      (nth 100)))
;;=> {0 ([3.5 4.5] [4.5 5] [3.5 5] [5 7] [3 4]), 1 ([1.5 2] [1 1])}

assign-clusters

(assign-clusters f mu x)

Returns cluster assignments based on the closest centroid to each point.

k-means

(k-means k f points)

Returns a lazy sequence of a clustering of points using the distance function f, represented as a map from cluster id to a collection of points, at each iteration of k-means.

k-means-seq

(k-means-seq k f points centroids)

update-centroids

(update-centroids k clusters)

Returns updated centroids based on the average of points in each cluster.