Skip to content
AI.info

Unsupervised learning

Spectral Clustering and Graph Cuts

Understand affinity matrices, graph Laplacians, spectral embeddings, graph-cut intuition, and the sensitivity of spectral clustering.

By the end you can

Comparison

Coordinate-space and graph-space partitioning

Spectral methods gain flexibility by moving the structural assumption into the affinity graph. Each of the three approaches below buys that flexibility at a different price. For the third, the price has been measured.

Modularity-based community detection has a proven blind spot. It can hide well-defined substructure inside a module whose internal links number about sqrt(2L) or fewer, where L is the network's total number of links. Fortunato and Barthelemy proved that in PNAS in 2007, and their abstract does not hedge: “We find that modularity optimization may fail to identify modules smaller than a scale which depends on the total size of the network and on the degree of interconnectedness of the modules, even in cases where modules are unambiguously defined.”

A different research group revisited the same limit in 2010 and added a second problem to the first. The modularity function typically admits an exponential number of distinct high-scoring solutions. So a high score does not identify a partition.

FigureComparison · 3 columns

K-Means on original features

Uses nearest centroids in the observed coordinate geometry.

  • Fast and scalable
  • Creates convex Voronoi regions
  • Avoids eigenvector computation
  • Depends directly on feature distances

Spectral clustering

Uses eigenvectors of a similarity graph before partitioning.

  • Can separate non-convex connected structure
  • Depends on graph construction
  • Requires K or a selection rule
  • Can be expensive for large datasets

Graph community detection

Optimizes a network partition objective on an observed graph.

  • Works directly with network edges
  • May use modularity or related quality functions
  • Faces resolution limits
  • Need not start from vector distances

Analogy

Finding communities through vibration modes

Struck once, a connected structure vibrates in slow patterns. Parts that move together reveal weakly separated regions of the structure.

A physical circuit already exists. A similarity graph does not: it is constructed from data and parameters. Changing an edge rule can move the apparent bottleneck before spectral optimization has begun.

Spectral coordinates reveal organization encoded in the graph, not beyond it.

Thirty-four people, two factions, one node wrong

Zachary's karate club is not a demonstration built to be separable. It is a real friendship network of 34 nodes — 77 or 78 edges, depending on an ambiguous typo in the 1977 study — whose members split into two factions. Zachary published it in 1977, and the Netzschleuder network catalogue has carried it, with its faction metadata, ever since. The ground truth is not a label the analyst assigned. It is the split that actually happened.

In June 2002 Girvan and Newman ran their community-detection algorithm on that graph and compared the top-level split it produced against the real division. The result is a countable error: “Only one node, node 3, is classified incorrectly.” One node out of 34.

That number is the whole point of the example, and it exists only because a real answer was there to check against. A graph-space method transformed the affinity structure it was given, and someone counted how far the result sat from the truth. Where no such answer exists — which is most of the time — the method still produces a clean-looking partition. Nothing in the output tells you whether it was right in 33 places out of 34 or wrong everywhere.

Spectral clustering is only as credible as the graph whose spectrum it analyzes.

Visual

The spectral clustering pipeline

Spectral clustering converts local affinity into a new coordinate system before applying a conventional partition. Two of these five steps are not computations but choices. The two most widely used implementations disclose them in their own documentation.

scikit-learn's user guide states the constraint at step 5 before the reader has reached it: “The present version of SpectralClustering requires the number of clusters to be specified in advance. It works well for a small number of clusters, but is not advised for many clusters.” The same chapter documents SpectralClustering as solving a convex relaxation of the normalized-cuts problem, and lists its scalability as “Medium n_samples, small n_clusters”.

MATLAB exposes the same switches in spectralcluster, in its Statistics and Machine Learning Toolbox. k is a required positive integer. LaplacianNormalization takes 'none', 'randomwalk' (the default) or 'symmetric' — that is step 2, with its three options named. Each row of the eigenvector matrix V is then clustered by k-means, the default, or by k-medoids, which is step 5. Two vendors, independently, made the same two decisions the user's responsibility.

FigureProcess · 5 steps
  1. 1. Construct affinity

    Build a similarity matrix or sparse neighborhood graph.

  2. 2. Form a Laplacian

    Combine adjacency and degree information into a graph operator.

  3. 3. Compute eigenvectors

    Extract low-frequency spectral directions associated with graph organization.

  4. 4. Embed nodes

    Represent observations using selected eigenvector coordinates.

  5. 5. Partition embedding

    Apply K-Means or another method in the spectral space.

The final labels depend on both the graph and the partition performed after embedding.

Example

Where spectral decisions enter the result

Several apparently technical choices can change the partition qualitatively. One of them has a theorem behind it rather than a caution.

The graph-derived distance most often invoked to justify affinity graphs degenerates at scale. In large random neighborhood graphs — epsilon-graphs, kNN graphs and Gaussian similarity graphs alike — the rescaled hitting time converges to 1/d_v and the rescaled commute time to 1/d_u + 1/d_v. That is the vertex degrees, and nothing else. Von Luxburg and two colleagues proved it in 2014, in the Journal of Machine Learning Research, and their abstract draws the consequence for practice: “In these cases, hitting and commute times do not provide information about the structure of the graph, and their use is discouraged in many machine learning applications.” Rupchin and Mucha restated the same collapse for dense random geometric graphs in 2026, writing that in dense settings “the role of the geometry disappears and commute times degenerate to a sum of inverse degrees”.

  • Affinity bandwidth: a narrow kernel fragments the graph, while a broad kernel creates shortcuts between curved groups. And once the graph is large and dense enough, the commute times that were meant to justify the bandwidth converge to 1/d_u + 1/d_v and stop describing the graph at all.
  • Neighbor count: small k preserves local precision but may disconnect legitimate regions; large k can erase manifold boundaries. The 2014 degeneracy result covers kNN graphs as explicitly as it covers epsilon-graphs.
  • Normalization: different graph Laplacian variants change the treatment of node degree and cluster volume. MATLAB's spectralcluster exposes exactly three of them — 'none', 'randomwalk' (the default) and 'symmetric' — and the default is a choice someone made, not a property of the data.
  • Eigenvector count: selecting K coordinates assumes a target partition size and can miss weaker multiscale structure. That is why both scikit-learn and MATLAB make the number of clusters a required argument rather than something the method infers.
  • Final K-Means: the spectral embedding still has initialization and partition variability, and it should be measured. k-medoids on the identical rows of V is a different partition of the same embedding.

Key idea

A beautiful spectral split can be an affinity artifact

Sparse graphs, duplicated points, hubs, and kernel scale can manufacture bottlenecks that eigenvectors amplify. The resulting partition may look dramatically clean even when nearby graph choices disagree.

How wrong can it be? Guattery and Miller answered by construction rather than by warning, in 1998. Their abstract: “In particular, we consider two popular spectral separator algorithms, and provide counterexamples that show these algorithms perform poorly on certain graphs.” The counterexamples are bounded-degree planar graphs — ladders with half their rungs removed. On them the optimal bisector cuts a constant number of edges, while the second-eigenvector bisection cuts on the order of n. Nor is the fix to take a few more eigenvectors: they show that using a constant number of the smallest ones does no better. Urschel and Zikatanov later proved a lower bound on the maximal spectral bisection error, growing with the square of the graph's order.

The hubs in the first sentence are likewise measured rather than suspected. In high dimensions, a few points turn up in many other points' neighbor lists. A 2010 paper in the Journal of Machine Learning Research opened the subject: “This paper explores a new aspect of the dimensionality curse, referred to as hubness, that affects the distribution of k-occurrences: the number of times a point appears among the k nearest neighbors of other points in a data set.” That distribution becomes considerably skewed as dimensionality increases. So a kNN affinity graph acquires hubs by construction, not by accident. Feldbauer and Flexer compared the remedies across 50 public data sets in 2019: scaling and density-gradient-flattening hubness reductions consistently improve hubness and nearest-neighbour classification accuracy, while centering approaches do so only under specific settings.

Audit components, degree distribution, bridges, and parameter stability before interpreting the split. Compare against direct graph and coordinate baselines.

Eigenvectors can sharpen both real structure and graph-construction mistakes.

Steps

Qualify a spectral clustering result

The graph, the spectrum, and the final partition each need independent checks. The last of those includes checking that the clusters you produced are connected, which scoring well does not imply.

The Louvain algorithm may yield arbitrarily badly connected communities. A 2019 paper in Scientific Reports demonstrated the gap: “In our experimental analysis, we observe that up to 25% of the communities are badly connected and up to 16% are disconnected.” On the Amazon, DBLP and Web UK networks the averages were 23%, 16% and 14% badly connected. The same authors then introduced the Leiden algorithm and proved that it returns communities guaranteed to be connected. Scanpy's own documentation now tells users to “Cluster cells using the Leiden algorithm, an improved version of the Louvain algorithm”, citing that paper.

So step 1 inspects the components of the graph you built, and step 4 inspects the components of the partition you produced. They are different audits. A widely used method failed the second one on a quarter of its output before anyone measured it.

FigureProcess · 5 steps
  1. 1. Validate affinity

    Review neighbor examples, graph degree, components, and scale sensitivity.

  2. 2. Inspect spectrum

    Look for eigenvalue gaps cautiously and compare several target dimensions.

  3. 3. Review embedding

    Check whether separation survives seeds and plausible graph variants.

  4. 4. Compare partitions

    Measure stability and agreement against K-Means, density, and hierarchical baselines.

  5. 5. Test scalability

    Record graph memory, eigen-solver cost, approximation error, and update strategy.

Spectral clustering moves the hard question upstream

Shapes that centroid geometry misses become representable once the data is embedded, but only if the graph is meaningful. Choosing the affinity becomes the central modeling decision. Every result in this lesson attaches to that decision rather than to the eigenvectors: the commute times that stop carrying structure in large neighborhood graphs, the hubs a kNN rule creates in high dimensions, the ladders on which the second eigenvector cuts on the order of n edges instead of a constant number.

Use spectral clustering when connectivity is the right notion of structure and the graph can be defended. Where a ground truth exists, count the errors against it, as was done on 34 nodes and one misclassification. Otherwise the extra mathematics may only conceal an arbitrary neighborhood choice.

The graph is the model; the eigenvectors are its lens.

Case

The NP-completeness proof in the appendix

The normalized cut cannot be solved outright, and the paper that introduced it says so. Shi and Malik published the criterion in 2000, in IEEE Transactions on Pattern Analysis and Machine Intelligence. Their appendix carries a proof supplied to them by Christos Papadimitriou: “Proposition 1 [Papadimitrou 97]. Normalized Cut (NCUT) for a graph on regular grids is NP-complete.” Their abstract then claims something narrower: “We show that an efficient computational technique based on a generalized eigenvalue problem can be used to optimize this criterion.” What the eigenvectors deliver is a relaxation of that problem. Not a solution to it.

Case

What spectral clustering actually solves

Cutting a graph in the cheapest place is easy. Requiring the pieces to be balanced is what breaks it. Von Luxburg's 2007 tutorial on spectral clustering puts the difficulty plainly: “introducing balancing conditions makes the previously simple to solve mincut problem become NP hard, see Wagner and Wagner (1993) for a discussion”. She then names the trade in one sentence. “Spectral clustering is a way to solve relaxed versions of those problems.”

Key takeaways