K-Means partitions
n samples into
K mutually exclusive hard clusters by coordinate descent on the within-cluster sum of squares (WCSS) objective
J=∑k=1K∑x∈Ck∥x−μk∥2.Each iteration alternates two steps: ① assignment — fix centroids, assign each
x to the nearest one,
c(x)=argmink∥x−μk∥; ② update — fix assignments, set each centroid to the cluster mean
μk=∣Ck∣1∑x∈Ckx.Both steps never increase
J, so the algorithm always converges — but only to a local optimum; each round costs
O(nKd), total
O(nKdT) with
T iterations.