Skip to main content
`Ctrl`+`K`

# louvain_partitions

louvain_partitions(G, weight='weight', resolution=1, threshold=1e-07, seed=None)

  Yields partitions for each level of the Louvain Community Detection Algorithm

  Louvain Community Detection Algorithm is a simple method to extract the community structure of a network. This is a heuristic method based on modularity optimization. [1]

  The partitions at each level (step of the algorithm) form a dendrogram of communities. A dendrogram is a diagram representing a tree and each level represents a partition of the G graph. The top level contains the smallest communities and as you traverse to the bottom of the tree the communities get bigger and the overall modularity increases making the partition better.

  Each level is generated by executing the two phases of the Louvain Community Detection Algorithm.

  Be careful with self-loops in the input graph. These are treated as previously reduced communities – as if the process had been started in the middle of the algorithm. Large self-loop edge weights thus represent strong communities and in practice may be hard to add other nodes to. If your input graph edge weights for self-loops do not represent already reduced communities you may want to remove the self-loops before inputting that graph.

  Parameters:
    G NetworkX graph
    weight string or None, optional (default=”weight”)

      The name of an edge attribute that holds the numerical value used as a weight. If None then each edge has weight 1.

    resolution float, optional (default=1)

      If resolution is less than 1, the algorithm favors larger communities. Greater than 1 favors smaller communities

    threshold float, optional (default=0.0000001)

      Modularity gain threshold for each level. If the gain of modularity between 2 levels of the algorithm is less than the given threshold then the algorithm stops and returns the resulting communities.

    seed integer, random_state, or None (default)

      Indicator of random number generation state. See Randomness.

  Yields:
    list

      A list of sets (partition of `G`). Each set represents one community and contains all the nodes that constitute it.

  See also

  `louvain_communities`

  References

  [1]

  Blondel, V.D. et al. Fast unfolding of communities in large networks. J. Stat. Mech 10008, 1-12(2008)