Abstract: K-Means++ and its distributed variant K-Means|| have become de facto tools for selecting the initial seeds of K-means. While alternatives have been developed, the effectiveness, ease of implementation, and theoretical grounding of the K-means++ and || methods have made them difficult to "best" from a holistic perspective. By considering the limited opportunities within seed selection to perform pruning, we develop specialized triangle inequality pruning strategies and a dynamic priority queue to show the first acceleration of K-Means++ and K-Means|| that is faster in run-time while being algorithmicly equivalent. For both algorithms we are able to reduce distance computations by over 500x. For K-means++ this results in up to a 17x speedup in run-time and a 551x speedup for K-means||. We achieve this with simple, but carefully chosen, modifications to known techniques which makes it easy to integrate our approach into existing implementations of these algorithms.
Introduction
K-means clustering is a fundamental tool in data science, but its performance is highly sensitive to the initial selection of cluster centers, or "seeds." The K-Means++ algorithm is the industry standard for seed selection due to its theoretical "log-optimal" guarantees. However, K-Means++ is computationally expensive, requiring $O(nk)$ distance computations. In high-performance environments, seed selection can consume nearly half of the total execution time. This paper introduces the first exact acceleration for K-Means++ and its distributed variant, K-Means||, achieving significant speedups without altering the final output.
Methodology
The proposed acceleration relies on three primary innovations designed to minimize redundant distance calculations while maintaining algorithmic equivalence.
Triangle Inequality Pruning
By tracking distances between newly selected means and previous means, the algorithm utilizes the triangle inequality to skip calculations for points that cannot possibly be closer to the new mean than their current nearest center. This adaptation of a classic K-means trick significantly reduces the computational load during the iterative seeding process.
The "Dirty" Dynamic Priority Queue
Standard K-Means++ requires a full pass over the dataset to normalize probabilities before selecting each seed. The author replaces this with a weighted sampling strategy using a dynamic priority queue.
The core insight is that a point's distance to its nearest center can only decrease as more centers are added. By using a "dirty" flag system, the algorithm only updates queue items when absolutely necessary. If the top item is "clean," it is guaranteed to be the correct next seed, allowing the algorithm to ignore the majority of the dataset during sampling.
NearestInRange Queries for K-Means||
For the distributed variant, the author utilizes Vantage Point (VP) trees modified for "NearestInRange" queries. By using the current known distance to the closest mean as a search radius, the tree can prune massive branches of the search space even when processing small batches of new points.
Key Results
The approach was evaluated on 11 diverse datasets, including massive-scale sets like HIGGS (11M samples) and Web (45M samples). The modifications proved to be "Pareto improvements," consistently matching or exceeding the performance of original implementations across all tests.
Key performance metrics include:
- Distance Reductions: Distance computations were reduced by over 500x on several datasets.
- Wall-Clock Speedup: K-Means++ achieved up to a 17x speedup (Covertype dataset), while K-Means|| saw a massive 551x speedup (Activity Recognition dataset).
- Scalability: Speedups generally improved as the number of clusters ($K$) increased, making the method particularly valuable for large-scale tasks where $K \ge 20,000$.
Conclusion
By combining triangle inequality pruning with a novel lazy-update priority queue, this work provides a significant, exact acceleration for standard K-means initialization. The approach avoids hardware-level bottlenecks like subnormal floating-point logic and is easily integrated into existing machine learning pipelines, offering substantial time savings for large-scale clustering problems.
Summary updated