Unsupervised learning
Graph Community Detection and Network Partitions
Study modularity, Louvain and Leiden-style optimization, graph weights, resolution limits, and robust community interpretation.
By the end you can
- Distinguish community detection on observed networks from clustering vectors by distance
- Explain modularity as comparison with a graph null model
- Recognize resolution limits, disconnected communities, and stochastic optimization effects
- Validate network partitions through stability, edge semantics, and downstream use
Analogy
Finding neighborhoods from roads rather than coordinates
Neighborhoods defined by how streets connect look nothing like neighborhoods defined by straight-line distance. A river crossing, highway, or footpath can matter more than physical proximity.
Dense connection is not the same thing as social cohesion or shared identity. Graph edges may represent transactions, automation, conflict, or measurement artifacts. The algorithm sees only the edges it was handed.
A community is a pattern of edges, not a guaranteed social group.
Key idea
Modularity has a resolution limit
A quality function can merge small communities inside a large network. It does that even when those groups are internally meaningful. Changing the resolution parameter can reveal them, but no single setting is universally correct.
In the two most-used single-cell toolkits the setting is supplied for you. scanpy's sc.tl.leiden ships resolution=1 in version 1.12.4, documented as “A parameter value controlling the coarseness of the clustering. Higher values lead to more clusters”, and citing Traag and colleagues (2019). The Satija Lab's Seurat tutorial for the PBMC3K dataset (Seurat 5.5.1) hands over a rule of thumb instead: “We find that setting this parameter between 0.4-1.2 typically returns good results for single-cell datasets of around 3K cells.” Its clustering step applies modularity optimization with the Louvain algorithm as its default. So in the field's most-run pipelines, the granularity of the published cell types is a library default and a tutorial's range. Nobody in the analysis chose that number. It is precisely the number a resolution sweep exists to interrogate.
Inspect partitions across resolutions and compare known scale expectations. Report multilevel alternatives when the network supports several granularities.
Optimization at one resolution can hide legitimate smaller structure.
Case
Identical cliques joined by single links, merged anyway
Take a network built of identical cliques, each joined to the next by a single link. Its substructure could not be plainer. Modularity optimization merges the cliques anyway.
That was proved in 2007, in PNAS, by Fortunato and Barthélemy. Modularity optimization “may fail to identify modules smaller than a scale” that is fixed by the size of the network. It fails “even in cases where modules are unambiguously defined”. The authors' preprint of the same result adds where the danger concentrates: the risk is highest when a module's internal links number about the square root of twice the total links in the graph. The limit is a property of the objective, not of a bad implementation of it.
A social community made from automated notifications
A collaboration graph connects employees whenever one system sends another a notification, and community detection then finds large “teams” that mainly reflect automated workflows rather than human collaboration. A graph algorithm partitions the edges it receives. If edge semantics are wrong, a strong modularity score organizes the wrong relation efficiently.
Nothing downstream can recover from this. The score, the resolution sweep, the stability check and the picture are all computed on the relation that was recorded. Every one of them will look healthy.
Network structure begins with a defensible definition of nodes and edges.
Visual
The objects behind a community partition
Community detection depends on how somebody built the graph, before any optimization begins. Each layer carries a documented failure of its own. The null model is where Fortunato and Barthélemy's resolution limit bites. The quality function is the Q whose degeneracy Good and colleagues measured: exponentially many high-scoring partitions, and no clear global maximum. The optimization heuristic is usually the only layer a report names.
- 01
Nodes
People, accounts, documents, proteins, transactions, or other entities.
- 02
Edges
Interactions, similarities, citations, flows, or shared attributes with direction and weight.
- 03
Null model
A baseline graph expectation used by modularity-style objectives.
- 04
Quality function
A score that rewards more within-community connection than expected.
- 05
Optimization heuristic
A procedure such as Louvain or Leiden that searches for a high-scoring partition.
A community is defined relative to edge semantics and a comparison model.
Comparison
Louvain-style and Leiden-style optimization
Both seek strong graph partitions. Their refinement behavior differs, and for Louvain the difference has been measured rather than asserted.
Louvain's claim to scale is a runtime. In 2008 Blondel and colleagues partitioned a web graph of 118 million nodes and more than one billion links in 152 minutes. A .uk sub-network of 39 million nodes and 783 million links took 12 minutes. Their introduction puts it plainly: “identifying communities in a 118 million nodes network took only 152 minutes”.
The same paper ran on a Belgian mobile-phone network of 2.6 million customers, weighted by total calls over a six-month period. The method returned a hierarchy of six levels. Its top level held 261 communities of more than 100 customers, about 75% of all customers. Of the 36 communities larger than 10,000 customers, every one had more than 85% of its members speaking the same language — except one, sitting at the interface between the French and Dutch clusters. That exception is what validating a partition against a known attribute looks like when it is written in numbers rather than adjectives.
Two independent benchmarks on Lancichinetti–Fortunato–Radicchi graphs rate the method highly. Lancichinetti and Fortunato reported in 2009 that “three recent algorithms introduced by Rosvall and Bergstrom, Blondel et al. and Ronhovde and Nussinov, respectively, have an excellent performance, with the additional advantage of low computational complexity, which enables one to analyze large systems.” Yang and colleagues tested eight algorithms in 2016 on such graphs of roughly 200 to 32,000 nodes. Taking accuracy and computing time together, they concluded that the Multilevel algorithm proposed by Blondel et al. outperformed all the others they examined. The same study found that for the larger networks in that range, roughly 6,000 to 32,000 nodes, Infomap and Multilevel are very likely to return the wrong number of communities. A ranking holds in part of the parameter space, not across all of it.
Leiden adds a refinement phase before aggregation. It buys a guarantee Louvain does not offer, at the same cost in modeling choices: the objective, the resolution and the graph construction are all still yours to defend. A spectral partition relaxes the problem differently and can expose bottlenecks, but shares the same dependence on how the graph was built.
Louvain
Moves nodes locally and aggregates communities iteratively.
- Scales to large networks
- Optimizes modularity or related objectives
- Can produce poorly connected communities
- Is stochastic and order-sensitive
Leiden
Adds a refinement phase before aggregation.
- Improves community connectivity
- Often finds higher-quality partitions
- Still depends on objective and resolution
- Does not eliminate stochastic variability
Spectral partition
Uses graph eigenvectors and a later cut.
- Provides a different relaxation
- Can expose bottlenecks
- May be costly at scale
- Shares sensitivity to graph construction
Steps
Audit a graph community analysis
Separate edge construction, objective selection, optimization, and interpretation.
Step 4 is not hygiene, and the reason is a result about the objective itself. Good and colleagues showed in 2010 that “the modularity function Q exhibits extreme degeneracies: it typically admits an exponential number of distinct high-scoring solutions and typically lacks a clear global maximum”. There is no single best partition waiting to be found. So two heuristics — or two seeds of one heuristic — can disagree about the modular structure of the same network while both score well. A 2021 NeuroImage review by Zamani Esfahlani and colleagues restates the property as routine and prescribes the working fix: the number of nearly-optimal partitions grows exponentially with network size, so build a consensus over an ensemble of near-optimal solutions rather than reporting one run.
Steps 3 and 5 have a canonical worked example. A university karate club split after a disagreement between its administrator and its instructor, who left and started a new club taking about half the original members with him. Wayne W. Zachary had observed 34 members of that club over a period of two years and recorded their ties; his study was published in 1977. Girvan and Newman's edge-betweenness algorithm, published in PNAS in 2002, reproduced the division against the externally recorded outcome. As they report of the karate club network, “Only one node, node 3, is classified incorrectly.” One member of 34 is the standard the reference-group check is capable of reaching — when a real outcome was recorded, and when the edges were the interactions that produced it.
1. Define graph semantics
Document node identity, edge event, direction, weight, time window, and exclusions.
2. Build graph variants
Test thresholds, aggregation periods, and normalization of high-activity nodes.
3. Sweep resolution
Compare community sizes, connectivity, persistence, and known reference groups.
4. Repeat optimization
Measure variation across seeds and node order, aligning partitions before comparison.
5. Inspect edge evidence
Review internal and boundary links for selected communities.
6. Test downstream value
Evaluate routing, discovery, intervention, or compression benefits under held-out data.
Example
Network choices that rewrite communities
A partition should be read with the graph-building policy attached.
- Edge threshold: Removing weak interactions fragments a network, while retaining every contact can merge unrelated populations.
- Direction: Follower, citation, and payment networks lose important structure when converted carelessly to undirected edges.
- Weight: One hundred automated messages should not necessarily count like one hundred deliberate collaborations. Blondel and colleagues weighted their mobile-phone edges by total calls, which is a decision about what a tie is, not a formatting step.
- Temporal aggregation: A yearly graph can combine several short-lived communities that never existed simultaneously. The Belgian network's six-month window is a claim that a tie in month one and a tie in month six belong to the same graph.
- Resolution parameter: Higher resolution can split broad communities, and lower resolution can absorb small meaningful groups. That is why a default of resolution=1, or a range of 0.4-1.2, is a starting point to sweep, not a finding.
Community detection is graph modeling, not merely graph mining
The partition reflects which interactions were recorded, how they were weighted, and what the null model considers surprising. A high score cannot validate those upstream decisions.
The standard temptation is to check a partition against the labels already attached to the nodes — department, discipline, country, cell type — and to call agreement validation and disagreement error. That route was closed in Science Advances in 2017. Peel and colleagues state it directly in their abstract: “Here, we show that metadata are not the same as ground truth, and that treating them as such induces severe theoretical and practical problems.” The same paper proves a No Free Lunch theorem for community detection: no algorithm is optimal across all community detection tasks. A method that wins on one network has no claim on the next. Hric and colleagues had already measured the gap empirically in 2014, finding that traditional community detection methods fail to recover metadata groups in many large networks — a marked separation between structural communities and metadata groups. Zachary's club, with one member of 34 misassigned, is the memorable case precisely because it is not the usual one.
Use community labels as summaries of network structure. Claims about identity, coordination, or influence require additional evidence and often a causal design.
The strongest community report explains the graph before explaining the groups.
Case
Up to a quarter of Louvain communities were badly connected
The Louvain algorithm “may yield arbitrarily badly connected communities”. That is not a worry. It is a count. In the experiments behind a 2019 Scientific Reports paper, up to 25% of communities were badly connected, and up to 16% were disconnected outright. Traag and colleagues propose Leiden instead, which “yields communities that are guaranteed to be connected”.
A badly connected community is one whose members are better attached to other communities than to their own. Such a partition can still score well on modularity — the same modularity that, at a scale set by the size of the network, cannot see small modules at all.
Figure
Key takeaways
- Community detection partitions an observed graph, not a generic feature matrix. Node identity, edge event, direction, weight and time window settle the answer before optimization begins.
- Louvain's scale is a measured runtime: a web graph of 118 million nodes and more than one billion links in 152 minutes. Its top ranking on LFR benchmark graphs breaks down for the larger graphs, where Infomap and Multilevel are very likely to return the wrong number of communities.
- Modularity is relative to a null model, and it carries the resolution limit Fortunato and Barthélemy proved in 2007: modules are merged even when they are unambiguously defined.
- Leiden's refinement yields communities guaranteed to be connected. In the Louvain partitions Traag and colleagues examined, up to 25% of communities were badly connected and up to 16% disconnected.
- Modularity typically lacks a clear global maximum and admits exponentially many high-scoring partitions. Repeated runs and a consensus over near-optimal solutions are required, not optional polish.
- Metadata are not ground truth, and no algorithm wins everywhere. Girvan and Newman's karate club, with one member of 34 misassigned against a recorded split, is the exception; in large networks Hric and colleagues found structural communities and metadata groups markedly separate.