NetworkX

Previous topic

networkx.transitivity

Next topic

networkx.average_clustering

Quick search

networkx.clustering

clustering(G, nbunch=None, with_labels=False, weights=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

nbunch : container of nodes, optional

Limit to specified nodes. Default is entire graph.

with_labels: bool, optional :

If True return a dictionary keyed by node label.

weights : bool, optional

If True return fraction of connected triples as dictionary

Returns:

out : float, list, dictionary or tuple of dictionaries

Clustering coefficient at specified nodes

Notes

The weights are the fraction of connected triples in the graph which include the keyed node. Ths is useful for computing transitivity.