Articles /Network Graph Analysis /Part 2
Community Detection in Social Graphs
Modularity, Louvain, and stochastic block models for finding structure
Graph TheoryPythonCommunity DetectionNetwork Analysis
Articles /Network Graph Analysis /Part 2
Graph TheoryPythonCommunity DetectionNetwork Analysis
Most real networks are not uniform: they contain densely connected subgroups with sparser links between them. Identifying these communities reveals functional modules in biological networks, social circles in friendship graphs, and topic clusters in citation networks. This article covers the algorithmic and generative approaches to community detection, drawing on techniques used in the Calendar Graph project ↗.
A community (or cluster, or module) is a group of nodes more densely connected internally than externally. The intuition is simple, but formalizing it requires a quality function: a way to score a proposed partition. The most widely used is modularity.
Modularity Q compares the fraction of edges within communities to the expected fraction under a random null model. Values near 0 mean no better than random; values approaching 1 indicate strong community structure. The Louvain algorithm greedily optimizes modularity in two phases: local node moves followed by community aggregation, iterating until convergence. It scales well to large networks and remains a go-to baseline.

Where Louvain optimizes a heuristic score, Stochastic Block Models (SBMs) take a generative approach: they posit that each node belongs to a latent block, and edges form with probabilities that depend on block membership. Fitting an SBM means inferring which block assignment best explains the observed edges. SBMs can detect disassortative structure (groups that connect between more than within) that modularity-based methods miss.
Communities often nest: a university has departments, which have research groups, which have labs. Hierarchical methods: dendrogram-based agglomerative clustering or nested SBMs capture this multi-scale structure. The Calendar Graph project ↗ uses hierarchical clustering to reveal organizational layers in interaction networks.

Community detection maps directly onto organizational analysis. In a collaboration or communication graph, detected communities might reveal cross-functional teams, information silos, or informal influence groups. Comparing the algorithmic partition to the formal org chart often surfaces surprising structure: bridging individuals, isolated clusters, or shadow hierarchies. The Calendar Graph project ↗ applies these techniques to real organizational communication data.
Communities tell you which groups exist. The next question: which individual nodes matter most within and across those groups?
If you're exploring related work and need hands-on help, I'm open to consulting and advisory. Get in touch›