Basic analysis: degree distribution
• Calculate in (and out) degrees of a directed graph
• Then use matplotlib (pylab) to plot the degree distribution
in_degrees = cam_net.in_degree() # dictionary node:degree
in_values = sorted(set(in_degrees.values()))
in_hist = [in_degrees.values().count(x) for x in in_values]
plt.figure() # you need to first do 'import pylab as plt'
plt.grid(True)
plt.plot(in_values, in_hist, 'ro-') # in-degree
plt.plot(out_values, out_hist, 'bv-') # out-degree
plt.legend(['In-degree', 'Out-degree'])
plt.xlabel('Degree')
plt.ylabel('Number of nodes')
plt.title('network of places in Cambridge')
plt.xlim([0, 2*10**2])
plt.savefig('./output/cam_net_degree_distribution.pdf')
plt.close()
29
Basic analysis: clustering
coefficient
• We can get the clustering coefficient of individual nodes or all the nodes (but first
we need to convert the graph to an undirected one)
Dostları ilə paylaş: