Estimating the average clustering coefficient

From kindergarten onward, we have friends, close friends, best friends forever, social media friends, and other friends. A social network graph should, therefore, have clumps, unlike what you would observe at a high school party. The question that naturally arises is what would happen if we just invite a group of random strangers to a party or recreate this setup online? We would expect the probability of strangers connecting to be lower than for friends. In graph theory, this probability is measured by the clustering coefficient.

The average clustering coefficient is a local (single node) version of the clustering coefficient. The definition of this metric considers triangles formed by nodes. With three nodes, we can form one triangle, for instance, the three musketeers. If we add D'Artagnan to the mix, more triangles are possible, but not all the triangles have to be realized. It could happen that D'Artagnan gets in a fight with all three of the musketeers. In (8.5), we define a clustering coefficient as the ratio of realized and possible triangles and average clustering coefficient (8.6):

Estimating the average clustering coefficient

Getting ready

Install NetworkX with the instructions from the Introduction section.

How to do it...

The script is in the avg_clustering.ipynb file in this book's code bundle:

  1. The imports are as follows:
    import networkx as nx
    import dautil as dl
  2. Load the Facebook SPAN data into a NetworkX graph:
    fb_file = dl.data.SPANFB().load()
    G = nx.read_edgelist(fb_file,
                         create_using=nx.Graph(),
                         nodetype=int)
  3. Calculate the average clustering coefficient as follows:
    print('Average Clustering',
          nx.average_clustering(G))

We get the following result for the Facebook SPAN data:

Average Clustering 0.6055467186200871

See also

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset