K-means algorithm variation with equal cluster size

This might do the trick: apply Lloyd’s algorithm to get k centroids. Sort the centroids by descending size of their associated clusters in an array. For i = 1 through k-1, push the data points in cluster i with minimal distance to any other centroid j (i < jk) off to j and recompute the centroid i (but don’t recompute the cluster) until the cluster size is n / k.

The complexity of this postprocessing step is O(k² n lg n).

Leave a Comment