Community detection

Also known as: graph clustering · network community detection

On this page 7

Community detection is the task of partitioning the nodes of a network into groups that are densely connected internally and only sparsely connected to the rest of the graph. Also called graph clustering or network community detection, it is one of the oldest unsupervised problems in graph learning and a common preprocessing step for analytics and machine learning on graphs.

A community can represent a circle of friends, a functional protein complex, a topic cluster of web pages or a coordinated fraud ring. Because there is no single correct definition of a community, the field offers several objective functions and algorithms, each encoding a different idea of what a good group looks like.

What makes a group of nodes a community

The intuitive definition compares internal edge density with external edge density: members link to each other more often than to outsiders. Formal definitions turn this intuition into a measurable quantity, and the chosen quantity strongly shapes the result.

The most widely used measure is modularity, usually written Q. It compares the fraction of edges inside communities with the fraction expected in a random graph with the same degree sequence. Values range from about -0.5 to 1, and partitions of real networks with clear structure typically score between 0.3 and 0.7. Higher modularity means more edges fall inside groups than chance would predict.

Other criteria emphasize different properties, as the following table shows.

CriterionWhat it measuresTypical use
ModularityInternal edges versus a random baselineGeneral-purpose partitioning
ConductanceEdges leaving a group relative to its volumeFinding well-separated local clusters
Normalized cutBalanced cost of cutting between groupsSpectral clustering
Map equationDescription length of a random walkFlow-based networks
LikelihoodFit of a generative block modelStatistical inference
Common quality criteria for communities

Main families of community detection algorithms

Algorithms differ in how they search for good partitions and in which criterion they optimize. Exact optimization of modularity is NP-hard, so practical methods rely on greedy heuristics, spectral relaxations or statistical inference.

AlgorithmApproachScalabilityMain caveat
LouvainGreedy modularity merging in levelsMillions of edgesCan create disconnected communities
LeidenLouvain with a refinement phaseMillions of edgesStill bound to modularity limits
Label propagationNodes adopt the most common neighbor labelNear-linear timeUnstable across runs
Spectral clusteringEigenvectors of the graph LaplacianModerate graphsNeeds the number of groups
InfomapMinimizes the map equationLarge graphsSensitive to edge directions
Stochastic block modelBayesian fit of group connectivityModerate graphsHigher compute cost
Representative algorithms and their properties

The Leiden algorithm is now the common default for large undirected graphs because it guarantees connected communities and converges faster than Louvain. Stochastic block models are preferred when the analyst needs principled model selection or wants to detect structures other than dense clusters, such as core-periphery or bipartite patterns.

Community detection in graph learning pipelines

In modern graph machine learning, community detection plays three distinct roles: it is a task in its own right, a source of features, and a tool for scaling training.

  • Unsupervised clustering with embeddings: node embeddings from DeepWalk or node2vec can be clustered with k-means, which often recovers communities because random walks stay inside dense regions.
  • Learned clustering: graph neural networks can be trained with a differentiable modularity or cut objective, producing soft community assignments.
  • Graph partitioning for training: Cluster-GCN splits a large graph into dense clusters so that mini-batches keep most edges, which reduces memory use.
  • Features for downstream models: community membership and community size often improve node classification and link prediction.

The relationship with homophily is central. When connected nodes tend to share labels, communities align with classes and simple methods such as label propagation work well. Under heterophily, dense groups may mix classes, and community features become less useful.

Choosing a method for a given network

The right method depends on graph size, on whether communities may overlap, and on whether the goal is exploration or statistical evidence. The decision table below summarizes common situations.

SituationRecommended choiceReason
Large undirected social graphLeidenFast, connected, well tested
Nodes belong to several groupsOverlapping methods such as BigCLAMHard partitions hide overlap
Directed flows, such as citationsInfomapModels the flow of a random walk
Small graph, need uncertaintyBayesian stochastic block modelSelects the number of groups
Graph changes over timeDynamic or incremental methodsTracks splits and merges
Decision guide for community detection

Limitations and common misinterpretations

Community detection always returns an answer, even on a random graph with no real structure. Modularity optimization on random graphs can produce surprisingly high scores, so results should be compared with a null model or a significance test before interpretation.

  • Resolution limit: modularity cannot detect communities smaller than a scale set by the total number of edges, so small groups merge. A resolution parameter partly addresses this.
  • Degeneracy: many very different partitions can have nearly the same modularity, so a single run is not a stable answer.
  • Evaluation without ground truth: metadata such as departments or labels may not match structural communities; low agreement does not automatically mean the algorithm failed.
  • Randomness: greedy algorithms depend on node order and seeds, so consensus clustering over many runs is advisable.

When ground truth exists, results are compared with normalized mutual information or the adjusted Rand index. Both measures should be read together with the number and size of detected groups.

Stripped to the essentials

Picture a big map of people and their friendships. Some people know each other very well and form tight groups. These groups have only a few links to other groups.

Community detection is a way for computers to find those groups automatically. It looks at who is connected to whom and draws borders around the dense clusters. Nobody has to label the groups in advance.

The key point is simple. A group counts as a community when its members are far more connected to each other than chance would explain.

Where it is applied

A payments company builds a graph in which accounts are nodes and shared devices, card numbers or shipping addresses are edges. The graph holds about 5 million accounts and 20 million edges, and analysts suspect organized fraud rings hide inside it.

The team runs the Leiden algorithm with a raised resolution parameter, which produces many small communities. They then flag groups of 5 to 50 accounts with unusually high internal density and a high share of recent chargebacks. Community size, density and chargeback rate become features for a fraud classifier.

Investigators review the top-ranked groups and confirm several coordinated rings that individual account rules had missed. The main gain is earlier detection of whole networks of accounts rather than one account at a time.