Hands-on: Finding Communities (and Doubting Them)

Author

Sadamori Kojaku

Published

August 25, 2026

Running a community detection algorithm takes one line. Knowing whether to believe the output is the skill.

NoteWhere the code lives

This course keeps its lecture note free of runnable code. Everything you execute lives in a marimo notebook, so it stays interactive and reactive instead of being a wall of output frozen into a web page.

Run this notebook — it runs in your browser, with nothing to install and nothing to sign into. The first load takes a few seconds while Python itself is downloaded.

Prefer to work locally? The notebook is in the repository at notebooks/m05-clustering/coding.py. Run it with marimo edit notebooks/m05-clustering/coding.py.

What you will build

  1. Run Louvain, Leiden, label propagation and edge betweenness on the same network and compare the partitions.
  2. Implement modularity from its definition and check it against the library’s value.
  3. Visualize communities on a network layout.
  4. Score partitions against known labels with NMI and ARI.

What to watch for

  • Run Louvain several times with different seeds. The partitions will differ. That instability is the degeneracy problem, not a bug in your code.
  • Run modularity maximization on an Erdos-Renyi graph with no communities at all. Note the score you get, then reconsider the Q > 0.3 rule of thumb.
  • Build a network with two cliques joined by one edge, then add a third larger community and re-run. Watch the resolution limit merge the two cliques.