K-Means++ is an improved initialization for K-Means: the first centroid is chosen uniformly at random, then each subsequent centroid is sampled with probability proportional to the squared distance to the nearest already-chosen centroid, where
D(x)=mink∥x−μk∥:
P(x)=∑x′D(x′)2D(x)2.Squared-distance sampling spreads the initial centroids apart: the expected objective satisfies
E[J]≤8(lnK+2)JOPT, bounding the worst local optimum within
O(logK) of the optimal — at the cost of just one extra
O(nKd) round of distance computation.Choosing K: the elbow method (WCSS inflection point) and the silhouette score
s=max(a,b)b−a (
a = mean intra-cluster distance,
b = mean distance to the nearest other cluster; closer to 1 is better); for outlier-robust clustering use K-Medoids (centroids restricted to actual data points).