partition_quality(G, partition)[source]#

Returns the coverage and performance of a partition of G.

The coverage of a partition is the ratio of the number of intra-community edges to the total number of edges in the graph.

The performance of a partition is the number of intra-community edges plus inter-community non-edges divided by the total number of potential edges.

This algorithm has complexity \(O(C^2 + L)\) where C is the number of communities and L is the number of links.

GNetworkX graph

Partition of the nodes of G, represented as a sequence of sets of nodes (blocks). Each block of the partition represents a community.

(float, float)

The (coverage, performance) tuple of the partition, as defined above.


If partition is not a valid partition of the nodes of G.


If G is a multigraph;
  • for coverage, the multiplicity of edges is counted

  • for performance, the result is -1 (total number of possible edges is not defined)



Santo Fortunato. “Community Detection in Graphs”. Physical Reports, Volume 486, Issue 3–5 pp. 75–174 <>