- Introduced by
- Louvain: Blondel et al. (2008); Leiden: Traag et al. (2019); Girvan-Newman: Girvan & Newman (2002); Infomap: Rosvall & Bergstrom (2008)
- Year
- 2002–2019 (algorithm family)
- Type
- Graph-partitioning / clustering algorithm family
What does it do?
Community detection is a family of graph-partitioning algorithms that identify densely connected groups of nodes, called communities, within a network.
Early divisive methods such as Girvan–Newman edge-betweenness removal reveal hierarchical divisions of a network, and the modularity measure Q has become the standard quality criterion that Louvain and Leiden optimise. The Louvain method (Blondel et al., 2008) and its Leiden refinement (Traag et al., 2019) are the modularity-based algorithms most often applied, while Infomap compresses a random walk on the network to find communities. All variants address one question: which nodes cluster together more tightly among themselves than with the rest of the network?
The intuition behind the method
Imagine a large social network in which some people talk mostly to their immediate circle and only occasionally reach outside it. Community detection finds those circles automatically, without labelling them in advance. The algorithm rearranges nodes into groups so that connections within a group are dense and connections between groups are sparse. It does this by maximising modularity Q, or, in Infomap, by minimising the description length of a random walk on the network. The output is a partition: each node belongs to exactly one community, and the network can be displayed as a set of cohesive clusters.
History
Early divisive approaches, such as Girvan-Newman edge-betweenness removal, revealed hierarchical divisions of a network by iteratively removing edges with high betweenness. Modularity Q later became a standard quality criterion for partitions. Blondel et al. (2008) introduced the Louvain method, a two-phase greedy optimisation of modularity; it was demonstrated on a mobile phone network of about 2 million customers and a web graph of 118 million nodes. Traag, Waltman and van Eck (2019) reported that Louvain can produce communities that are not well connected and developed the Leiden algorithm, whose refinement step is designed to guarantee well-connected partitions. Infomap treats community detection as compressing a random walk on the network.
When to use it
Choose community detection when you have a network and want to find latent group structure without fixing the groups in advance. No statistical minimum network size applies. Some practitioners use about 20 nodes as a planning convention, but in smaller graphs apparent communities may reflect chance, so repeated runs and sensitivity checks become more important. The method is exploratory and unsupervised. It applies to weighted or unweighted graphs and needs no node attributes or distributional assumptions. For directed networks where flow matters, Infomap is the variant suited to the task. Louvain and Leiden are normally applied to undirected or symmetrised edge weights, so check whether your implementation offers a directed modularity variant before analysing a directed network. Do not use community detection when you already have specific groups to test, because a classification or model-based comparison fits that question better. Do not read a community partition as a statistical test that communities exist. Edge-weight definitions and network density strongly affect the partition, so these choices should be justified before the analysis is run.
Limitations and considerations
- Modularity optimisation is a heuristic that can settle in local optima, so different runs may return different partitions.
- Modularity has a resolution limit: in large networks, small but real communities can be merged into larger ones, so fine-grained structure may be hidden.
- The partition depends on how edge weights are defined, and alternative weighting schemes can produce substantively different communities.
- Girvan-Newman is computationally expensive, which makes it impractical for large networks, where Louvain or Leiden are preferable.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- The number of communities is not fixed in advance: Louvain, Leiden and Infomap determine it from the network structure, and Girvan-Newman exposes it through its dendrogram.
- Louvain is designed for large networks: the original paper (Blondel et al., 2008) applied the method to a mobile phone network of about 2 million customers and a web graph of 118 million nodes, and reported better computation time than other known community detection methods.
- Leiden adds a refinement step designed to keep every community internally connected, addressing a disconnected-community flaw that Traag et al. (2019) report for Louvain.
- The methods work on weighted or unweighted graphs and make no distributional assumptions about the data, because they operate only on the adjacency structure.
Applications
- Identifying research clusters in citation and co-authorship networks to map scientific fields.
- Detecting functional modules in protein-protein interaction networks in biology.
- Finding user communities in social media and communication networks for behavioural analysis.
- Segmenting customer networks in business and marketing to reveal cohesive customer groups.
- Discovering structural blocks in infrastructure, transport, or supply-chain networks.
How it works
How it works
The input is a graph whose nodes represent entities (people, web pages, proteins, citations) and whose edges represent relationships between them. Edges may be directed or undirected and may carry weights. The adjacency structure, meaning which nodes are connected and how strongly, is the only input the algorithms require. Node labels, classes or other attributes are not needed, although they can be used to check the results afterwards.
Each algorithm starts from an initial state. In Louvain and Leiden every node begins as its own singleton community. Girvan-Newman starts with the full network and iteratively removes the edge with the highest betweenness centrality, which gradually reveals the community structure. Infomap starts from a random-walk description of the network and encodes it with a two-level map to reduce the code length.
The core phase searches for a partition that maximises modularity Q (Louvain, Leiden) or minimises the map-equation code length (Infomap). Louvain greedily moves single nodes between communities to increase Q, then aggregates each community into a super-node and repeats. This scales well, but it can produce communities that are not internally connected. Leiden adds a refinement step designed to keep every community internally connected. Girvan-Newman records the dendrogram of splits, and the cut that maximises Q is selected. The number of communities emerges from the algorithm and does not have to be specified in advance.
The quality of the final partition is summarised by the modularity score Q, which ranges from −0.5 to 1 for undirected graphs. Q compares the observed number of within-community edges with the number expected in a random network that preserves the node degrees. Values above roughly 0.3–0.5 are often read as a sign of non-trivial community structure, but this is a rule of thumb rather than a formal threshold. Modularity optimisation can become trapped in local optima, so repeated runs are standard practice and the best result is usually reported. The partition should also be inspected visually and compared with any available node attributes or ground-truth labels to confirm that it is substantively meaningful.
Common pitfalls
- Treating a single run as the answer. Because the optimisation depends on node order and random choices, repeat the run and compare the partitions and their Q values before reporting.
- Assuming small communities do not exist because they are not reported. In large sparse networks the resolution limit can absorb them without any warning in the output.
- Applying modularity-based methods to very small graphs, where apparent communities may be artefacts of chance.
- Reading a high modularity score as proof of real social or biological groups. Q compares observed within-community edges with what a random graph with the same degrees would give. It is not a significance test, and the groups still need external validation.
Frequently asked questions
Which algorithm should I choose: Louvain, Leiden, Girvan-Newman, or Infomap?
Louvain is a fast, widely used baseline for large networks. Leiden is generally preferred when well-connected communities matter, because its refinement step is designed to keep each community internally connected. Girvan-Newman produces a dendrogram that is useful for hierarchical exploration but is too slow for large networks. Infomap is suited to directed or flow-based networks where the path a random walker takes is meaningful.
Do I need to specify the number of communities in advance?
No. Louvain, Leiden and Infomap determine the number of communities from the network structure. Girvan-Newman produces a full dendrogram from which any number of communities can be read off; the cut that maximises Q is usually selected.
How do I know whether the communities found are meaningful?
The modularity score Q is an internal quality measure. Values above roughly 0.3–0.5 are often read as a sign of non-trivial community structure, but this is a rule of thumb rather than a formal threshold, and it depends on network size and density. Communities should also be checked against domain knowledge, node attributes or external labels, because a high Q alone does not establish sociological or biological significance.
What happens if results differ across runs?
Modularity optimisation is a heuristic, and different runs can return slightly different partitions, especially with Louvain. Run the algorithm several times, compare the resulting partitions and their Q values, and report the highest-Q result together with how much the runs agreed. Leiden's refinement step is designed to make results more reliable than Louvain's, but repeated runs remain good practice.
Related methods
Sources
Blondel, V.D., Guillaume, J.-L., Lambiotte, R. & Lefebvre, E. (2008). Fast Unfolding of Communities in Large Networks. Journal of Statistical Mechanics, 2008(10), P10008.
Open DOI referenceTraag, V.A., Waltman, L. & van Eck, N.J. (2019). From Louvain to Leiden: Guaranteeing Well-Connected Communities. Scientific Reports, 9, 5233.
Open publication reference