NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

q-means: A quantum algorithm for unsupervised machine learning

Iordanis Kerenidis, Jonas Landman, Alessandro Luongo, Anupam PrakashNeurIPS 2019

Clustering is a cornerstone of unsupervised machine learning, but as datasets grow toward the exabyte scale, even simple algorithms like $k$-means struggle to keep up. In their NeurIPS 2019 paper, Kerenidis et al. introduce q-means, a quantum algorithm that promises to break the linear time barrier, offering an exponential speedup in the number of data points processed. Crucially, unlike many quantum algorithms that leave results trapped in quantum states, q-means outputs classical centroids, making it a powerful tool for future hybrid quantum-classical data pipelines.

The Bottleneck in Classical Clustering

The classical $k$-means algorithm is computationally expensive for massive datasets. Its complexity is roughly $O(Ndk)$, where $N$ is the number of points, $d$ is the number of features, and $k$ is the number of clusters. When $N$ reaches the billions, this linear dependence on the dataset size becomes a severe bottleneck.

While previous quantum clustering attempts existed, they faced two major hurdles:

  1. The "Output" Problem: They often produced the final cluster centers as quantum states. To actually read these centers into a classical computer, one would need so many measurements that any quantum speed advantage would be lost.
  2. The "Noise" Problem: Quantum computers are inherently non-deterministic and noisy. A direct translation of $k$-means does not account for the probabilistic nature of quantum distance estimation.

Methodology: Bridging Quantum and Classical

To overcome these challenges, the authors introduce a robust classical framework called $\delta$-$k$-means, which explicitly allows for noise in label assignment and centroid calculation. They then prove that their quantum algorithm, q-means, is a faithful implementation of this robust version.

The q-means algorithm follows four main steps per iteration:

  1. Centroid Distance Estimation: Using a Quantum Random Access Memory (QRAM) and Amplitude Estimation, the algorithm calculates the distance between all data points and all current centroids in superposition.
  2. Cluster Assignment: A quantum circuit finds the minimum distance for each point, effectively labeling them.
  3. Centroid State Creation: Using quantum linear algebra, the algorithm calculates the new barycenters (means) of these clusters, representing them as quantum states.
  4. Centroid Update (Tomography): This is the key innovation. The algorithm uses vector state tomography to efficiently convert these quantum states back into classical vectors. This allows the user to inspect the centroids and use them for the next iteration or in classical applications.

The paper also introduces q-means++, a quantum equivalent of the popular $k$-means++ initialization method, ensuring the algorithm starts with high-quality initial cluster centers.

Experimental Validation

Because fault-tolerant quantum hardware capable of running q-means does not yet exist, the authors evaluated the algorithm's logic using classical simulations of the $\delta$-$k$-means framework on two types of datasets:

  • MNIST: The classic dataset of 60,000 handwritten digits, preprocessed using PCA down to 40 dimensions.
  • Synthetic Data: Datasets consisting of well-separated Gaussian clusters to test convergence and precision guarantees.

Key Insights and Results

  • Exponential Speedup: The most striking insight is the algorithm's complexity. q-means operates in $O(\text{poly-log}(N))$ time. This means that doubling the number of data points only adds a marginal amount of time to the quantum execution, whereas it would double the time for a classical computer.
  • Embracing Noise: Instead of trying to make quantum distance estimation perfect (which is computationally expensive), the authors showed that $k$-means is naturally robust. By defining $\delta$-$k$-means, they proved that as long as the quantum noise is bounded, the algorithm will still converge to a valid clustering.
  • Performance Parity: Simulations on the MNIST dataset demonstrated that even with the noise levels expected in quantum computations ($\eta/\delta$ ratios around 20), q-means achieves accuracy virtually identical to classical $k$-means.
  • Convergence: The number of iterations required for q-means to converge is practically the same as the classical version, meaning the quantum speedup per iteration translates directly to a total overall speedup.

Limitations and Future Directions

The primary limitation of q-means is its stringent hardware requirements:

  1. Fault-Tolerant Quantum Computers: The depth of the circuits required for tomography and linear algebra is beyond what current Noisy Intermediate-Scale Quantum (NISQ) devices can handle.
  2. QRAM: The algorithm assumes the existence of Quantum RAM to load classical data into quantum states efficiently—a technology that remains in the early experimental stages.

Future work will focus on optimizing the algorithm's dependence on the condition number of the data matrix and exploring how q-means performs on datasets that are not well-clusterable, where the boundaries between clusters are more ambiguous.

Summary updated

BibTeX
@inproceedings{kerenidis2019q,
  author = {Iordanis Kerenidis and Jonas Landman and Alessandro Luongo and Anupam Prakash},
  title = {{q-means: A quantum algorithm for unsupervised machine learning}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2019},
}
Figure