louvain_partitions#

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

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 dendogram 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.

Parameters:
GNetworkX graph
weightstring 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.

resolutionfloat, optional (default=1)

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

thresholdfloat, 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.

seedinteger, 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.

References

[1]

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