Multi-Swap k-Means++

Lorenzo Beretta, Vincent Cohen-Addad, Silvio Lattanzi, Nikos Parotsidis

Abstract

The $k$-means++ algorithm is the industry standard for initializing cluster centers, providing an $O(\log k)$-approximation in expectation. While computationally efficient, it often falls short of the solution quality required for high-stakes applications. Recent advancements have suggested augmenting $k$-means++ with local search steps to achieve constant-factor approximations. In this paper, we introduce Multi-Swap $k$-Means++, an algorithm that generalizes local search by allowing the simultaneous swapping of multiple centers. We demonstrate that this approach achieves a $9 + \varepsilon$ approximation ratio—the theoretical limit for local search—while maintaining practical performance through a greedy heuristic. Our empirical results show significant quality improvements over existing methods on large-scale datasets.

Introduction

Clustering is a fundamental task in unsupervised learning, with the Euclidean $k$-means problem being its most prominent formulation. The goal is to partition $n$ points into $k$ clusters to minimize the sum of squared distances to the nearest cluster center. While the $k$-means++ seeding technique is widely used due to its speed, its theoretical guarantee is relatively weak.

To improve solution quality, researchers often employ local search, which iteratively replaces "bad" centers with better candidates. However, traditional local search is often computationally prohibitive or prone to getting trapped in local optima. Previous attempts to integrate local search with $k$-means++ sampling resulted in approximation constants that, while constant, were too large to be practically meaningful. Multi-Swap $k$-Means++ addresses this by expanding the local search neighborhood and optimizing the swap selection process.

Methodology

The core of our contribution lies in three distinct algorithmic advancements designed to balance theoretical tightness with computational feasibility:

  1. Multi-Swap Local Search (MSLS): Unlike standard local search which swaps a single center at a time, MSLS samples a set of $p$ new candidate points and attempts to swap them with $p$ existing centers. By increasing the size of the swap set, we significantly lower the approximation ratio.
  2. The "Averaging" Subroutine: To reach the near-optimal $(9 + \epsilon)$-approximation, we introduce a method that samples small groups of points and uses their centroid (average) as a candidate center. This approach better approximates the behavior of optimal centers, which are defined as the centroids of their respective clusters.
  3. MSLS-Greedy (MSLS-G): An exhaustive search for the optimal $p$ centers to remove is computationally expensive, scaling at $O(k^p)$. To make the algorithm viable for large-scale engineering, we developed a greedy variant. MSLS-G removes centers one-by-one based on which removal results in the smallest increase to the total cost. This heuristic allows the algorithm to scale to large values of $k$ without a significant loss in solution quality.

Theoretical Contributions

Our analysis provides a significant tightening of the theoretical bounds for local search in clustering. We improved the known approximation ratio for previous single-swap algorithms from over 2,000 down to 26.64. Furthermore, our multi-swap analysis demonstrates that as the number of swaps $p$ increases, the approximation ratio drops to 10.48. With the inclusion of the averaging subroutine, the algorithm reaches a $9 + \varepsilon$ approximation, which is the best possible result for any local search-based $k$-means algorithm.

Empirical Evaluation

We evaluated Multi-Swap $k$-Means++ on three large-scale, high-dimensional datasets: KDD-BIO (protein matching), RNA (RNA sequence pairs), and KDD-PHY (quantum physics). All datasets were min-max scaled to ensure feature parity during distance calculations.

Key Findings:

  • Solution Quality: MSLS-G (with $p$ values of 4, 7, and 10) consistently outperformed standard $k$-means++ by 20% to 30% in terms of total objective cost.
  • Comparison to State-of-the-Art: Compared to Single-Swap Local Search (SSLS), our multi-swap approach achieved a 10% lower cost while remaining computationally feasible for datasets containing nearly 500,000 points.
  • Heuristic Efficiency: One of the most significant empirical observations was that the greedy center-removal heuristic (MSLS-G) performed almost identically to exhaustive search (MSLS) in terms of quality, but at a fraction of the computational cost.
  • Persistence of Gains: The improvements gained during the seeding phase persisted even after applying Lloyd’s algorithm (the standard EM refinement), proving that better seeding leads to fundamentally better local optima.

Conclusion and Future Work

Multi-Swap $k$-Means++ provides a practical path to near-optimal clustering. By bridging the gap between fast seeding and exhaustive local search, it offers a robust tool for applications where solution quality is paramount. While the greedy variant is significantly faster than exhaustive search, it still carries more overhead than basic $k$-means++. Future research will focus on optimizing the "swap-in" bottleneck—specifically, finding more efficient ways to identify candidate centers without exhaustive sampling from the $D^2$ distribution.

Summary updated

BibTeX
@inproceedings{beretta2023multi,
  author = {Lorenzo Beretta and Vincent Cohen-Addad and Silvio Lattanzi and Nikos Parotsidis},
  title = {{Multi-Swap k-Means++}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2023},
  url = {https://openreview.net/forum?id=zGRWp7yRqd},
}
Figure