NetworkX

Previous topic

networkx.algorithms.cluster.transitivity

Next topic

networkx.algorithms.cluster.average_clustering

networkx.algorithms.cluster.clustering

networkx.algorithms.cluster.clustering(G, nodes=None, weighted=False)

Compute the clustering coefficient for nodes.

For each node find the fraction of possible triangles that exist,

c_v = \frac{2 T(v)}{deg(v)(deg(v)-1)}

where T(v) is the number of triangles through node v.

Parameters :

G : graph

A networkx graph

nodes : container of nodes, optional

Limit to specified nodes. Default is entire graph.

weighted : bool, optional

If True use weights on edges in computing clustering coefficients.

Returns :

out : float, dictionary or tuple of dictionaries

Clustering coefficient at specified nodes

Notes

Self loops are ignored.

References

[R103]Generalizations of the clustering coefficient to weighted complex networks by J. Saramäki, M. Kivelä, J.-P. Onnela, K. Kaski, and J. Kertész, Physical Review E, 75 027105 (2007). http://jponnela.com/web_documents/a9.pdf

Examples

>>> G=nx.complete_graph(5)
>>> print(nx.clustering(G,0))
1.0
>>> print(nx.clustering(G))
{0: 1.0, 1: 1.0, 2: 1.0, 3: 1.0, 4: 1.0}