Standard k-means++
Overview
Standard k-means++ is the classic k-means initialization algorithm that carefully seeds cluster centers using D² sampling to achieve an \(O(\\log k)\) approximation to the optimal k-means clustering.
When to use:
Small to medium datasets (n < 10,000)
When you need the baseline/reference implementation
When theoretical guarantees are critical
For comparison with faster approximations
Key advantages:
✅ Proven \(O(\\log k)\) approximation guarantee
✅ Simple and well-understood
✅ No hyperparameters to tune
✅ Baseline for comparing other algorithms
Python API
- kmeans_seeding.kmeanspp(X, n_clusters, *, random_state=None)[source]
Standard k-means++ initialization using D² sampling.
- Parameters:
- Returns:
Initial cluster centers
- Return type:
ndarray of shape (n_clusters, n_features)
Examples:
from kmeans_seeding import kmeanspp import numpy as np X = np.random.randn(1000, 20) centers = kmeanspp(X, n_clusters=10, random_state=42)
With scikit-learn:
from kmeans_seeding import kmeanspp from sklearn.cluster import KMeans centers = kmeanspp(X, n_clusters=10) kmeans = KMeans(n_clusters=10, init=centers, n_init=1) labels = kmeans.fit_predict(X)
Algorithm
D² Sampling
The algorithm selects k centers sequentially:
Choose first center uniformly at random
For each subsequent center:
Compute D²(x) = squared distance to nearest selected center
Sample new center with probability ∝ D²(x)
Add to selected centers
Time complexity: \(O(nkd)\) for n points, k centers, d dimensions
Space complexity: \(O(nd)\) for storing data
Approximation: \(\\mathbb{E}[\\Phi] \\leq O(\\log k) \\cdot \\Phi_k(X)\)
Advantages
Strong theoretical guarantees: Proven \(O(\\log k)\) approximation
No hyperparameters: Works out of the box
Deterministic quality: Given seed, always same quality
Simple implementation: Easy to understand and verify
Limitations
Slow for large data: \(O(nkd)\) becomes prohibitive
Sequential: Can’t easily parallelize center selection
No approximation: Must compute all distances exactly
When to Use Alternatives
Use faster alternatives when:
n > 10,000: RS-k-means++ or AFK-MC² are much faster
k > 100: Fast-LSH scales better with many clusters
d > 100: Fast-LSH optimized for high dimensions
Need speed: Any fast algorithm is 10-100× faster
Recommendation: Use standard k-means++ for: - Small datasets - Establishing baselines - When simplicity matters - Academic/research comparisons
See Also
RS-k-means++: Rejection Sampling - Fast approximation using rejection sampling
AFK-MC²: Adaptive Fast k-MC² - Fast approximation using MCMC
Fast-LSH k-means++ - Fast approximation using tree embedding
Algorithm Comparison - Detailed algorithm comparison