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

A Tutorial on Spectral Clustering

Ulrike von Luxburg

Abstract

Spectral clustering has become one of the most popular modern clustering algorithms. It is simple to implement, can be solved efficiently by standard linear algebra software, and very often outperforms traditional clustering algorithms such as the k-means algorithm. This tutorial provides a unified explanation of spectral clustering, detailing its mathematical foundations in graph theory and linear algebra, and offering practical guidance on its application.

Introduction

Spectral clustering often feels like a "black box" that magically works when traditional methods like k-means fail. In this seminal tutorial, Ulrike von Luxburg demystifies the algorithm, providing the mathematical intuition and practical guidance needed to move from "it just works" to "I understand why." Spectral clustering is a powerful technique that uses the eigenvalues and eigenvectors of graph matrices to perform dimensionality reduction before clustering. It excels at identifying complex, non-convex structures in data by treating data points as nodes in a similarity graph, effectively relaxing NP-hard graph partitioning problems into solvable linear algebra tasks.

Problem Statement

Traditional clustering algorithms, most notably k-means, rely on a "compactness" assumption—they expect clusters to be spherical or convex shapes. When faced with complex geometries (like intertwined spirals or concentric circles), k-means fails because it cannot "see" the connectivity of the data. The challenge in the field was that while spectral clustering was becoming popular, its theoretical foundations were scattered across different disciplines (machine learning, spectral graph theory, and computer science). This paper provides a unified tutorial to explain how the algorithms work, why they are related to graph cuts and random walks, and which version of the algorithm should be used in practice.

Methodology

The paper outlines a standard three-step pipeline for spectral clustering:

  1. Graph Construction: Transform data points into a similarity graph. Common methods include $\epsilon$-neighborhood graphs, k-nearest neighbor (k-NN) graphs, and fully connected graphs using a similarity function like the Gaussian kernel.
  2. The Laplacian Matrix: Compute a "Graph Laplacian" matrix ($L$). The paper distinguishes between the unnormalized Laplacian ($L = D - W$) and normalized Laplacians ($L_{sym}$ and $L_{rw}$).
  3. Eigen-decomposition: Extract the first $k$ eigenvectors of the Laplacian. These eigenvectors act as a new, low-dimensional representation of the data where clusters are much easier to separate.
  4. Final Clustering: Run a simple algorithm like k-means on this new coordinate system.

Key Insights and the Eigengap Heuristic

The "aha moment" of spectral clustering is realizing that finding the perfect "balanced cut" in a graph (RatioCut or Ncut) is computationally impossible (NP-hard). Spectral clustering is a mathematical "relaxation" that allows us to find an approximate solution using eigenvalues.

A critical practical tool is the eigengap heuristic. To choose the number of clusters ($k$), one should look for a "gap" in the sorted eigenvalues. If $\lambda_1 \dots \lambda_k$ are very small and $\lambda_{k+1}$ is relatively large, $k$ is likely the correct number of clusters.

Eigenvalues and eigenvectors for different Laplacian constructions.

Furthermore, the author strongly advocates for normalized spectral clustering (specifically the $L_{rw}$ version). Unnormalized clustering can produce "trivial" results where a single outlier is separated from the rest of the data, whereas normalized versions are more robust and statistically consistent. As shown in the figure above, the behavior of eigenvectors and eigenvalues varies significantly depending on the graph construction and normalization method.

Results and Discussion

Spectral clustering qualitatively demonstrates superiority over k-means by identifying non-convex clusters. Theoretical analysis shows that as the sample size $n \to \infty$, the results of normalized spectral clustering converge to a meaningful partition of the underlying space.

However, the method is not without limitations. There is no universal rule for choosing the "best" similarity graph or the scale parameter ($\sigma$) for the Gaussian kernel; these remain task-specific choices. While linear algebra is efficient, computing eigenvectors for very large matrices ($n > 10,000$) can be slow, though sparse matrix methods can mitigate this. Finally, in specific cases like the "cockroach graph," the spectral relaxation can be "arbitrarily bad" compared to the optimal discrete cut, though this is rare in real-world data.

Conclusion

Spectral clustering bridges the gap between graph theory and data analysis. By transforming data into a space defined by the Laplacian's eigenvectors, it reveals the intrinsic connectivity of the data, making it a robust and powerful choice for complex clustering tasks.

Summary updated

BibTeX
@article{luxburg2007tutorial,
  author = {Ulrike von Luxburg},
  title = {{A Tutorial on Spectral Clustering}},
  journal = {Stat. Comput.},
  year = {2007},
  doi = {10.1007/s11222-007-9033-z},
}
Figure