In graph theory, similarity is measured by the degree distribution. Degree is the number of connections a node has to other nodes. In a directed graph, we have incoming and outgoing connections and corresponding indegree and outdegree. Friends tend to have something in common. In graph theory, this tendency is measured by the assortativity coefficient. This coefficient is the Pearson correlation coefficient between a pair of nodes, as given in the following equation:
qk (distribution of the remaining degree) is the number of connections leaving node k. ejk is the joint probability distribution of the remaining degrees of the node pair.
The code is in the assortativity.ipynb
file in this book's code bundle:
import networkx as nx import dautil as dl
fb_file = dl.data.SPANFB().load() G = nx.read_edgelist(fb_file, create_using=nx.Graph(), nodetype=int)
print('Degree Assortativity Coefficient', nx.degree_assortativity_coefficient(G))
We get the following result for the Facebook SPAN data:
Degree Assortativity Coefficient 0.0635772291856
degree_assortativity_coefficient()
function at https://networkx.github.io/documentation/latest/reference/generated/networkx.algorithms.assortativity.degree_assortativity_coefficient.html (retrieved October 2015)