average_clustering(G, trials=1000, seed=None)¶
Estimates the average clustering coefficient of G.
The local clustering of each node in
Gis the fraction of triangles that actually exist over all possible triangles in its neighborhood. The average clustering coefficient of a graph
Gis the mean of local clusterings.
This function finds an approximate average clustering coefficient for G by repeating
ntimes (defined in
trials) the following experiment: choose a node at random, choose two of its neighbors at random, and check if they are connected. The approximate coefficient is the fraction of triangles found over the number of trials .
- GNetworkX graph
Number of trials to perform (default 1000).
- seedinteger, random_state, or None (default)
Indicator of random number generation state. See Randomness.
Approximated average clustering coefficient.
Schank, Thomas, and Dorothea Wagner. Approximating clustering coefficient and transitivity. Universität Karlsruhe, Fakultät für Informatik, 2004. http://www.emis.ams.org/journals/JGAA/accepted/2005/SchankWagner2005.9.2.pdf
>>> from networkx.algorithms import approximation >>> G = nx.erdos_renyi_graph(10, 0.2, seed=10) >>> approximation.average_clustering(G, trials=1000, seed=10) 0.214