networkx 2.8.2 Pypi GitHub Homepage
Other Docs
NotesParametersReturnsBackRef
clustering(G, nodes=None, weight=None)

For unweighted graphs, the clustering of a node $u$ is the fraction of possible triangles through that node that exist,

$$c_u = \frac{2 T(u)}{deg(u)(deg(u)-1)},$$

where $T(u)$ is the number of triangles through node $u$ and $deg(u)$ is the degree of $u$ .

For weighted graphs, there are several ways to define clustering . the one used here is defined as the geometric average of the subgraph edge weights ,

$$c_u = \frac{1}{deg(u)(deg(u)-1))} \sum_{vw} (\hat{w}_{uv} \hat{w}_{uw} \hat{w}_{vw})^{1/3}.$$

The edge weights $\hat{w}_{uv}$ are normalized by the maximum weight in the network $\hat{w}_{uv} = w_{uv}/\max(w)$ .

The value of $c_u$ is assigned to 0 if $deg(u) < 2$ .

Additionally, this weighted definition has been generalized to support negative edge weights .

For directed graphs, the clustering is similarly defined as the fraction of all possible directed triangles or geometric average of the subgraph edge weights for unweighted and weighted directed graph respectively .

$$c_u = \frac{2}{deg^{tot}(u)(deg^{tot}(u)-1) - 2deg^{\leftrightarrow}(u)} T(u),$$

where $T(u)$ is the number of directed triangles through node $u$ , $deg^{tot}(u)$ is the sum of in degree and out degree of $u$ and $deg^{\leftrightarrow}(u)$ is the reciprocal degree of $u$ .

Notes

Self loops are ignored.

Parameters

G : graph
nodes : container of nodes, optional (default=all nodes in G)

Compute clustering for nodes in this container.

weight : string or None, optional (default=None)

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

Returns

out : float, or dictionary

Clustering coefficient at specified nodes

Compute the clustering coefficient for nodes.

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}
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

networkx.algorithms.bipartite.cluster.average_clustering networkx.algorithms.cluster.clustering

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /networkx/algorithms/cluster.py#281
type: <class 'function'>
Commit: