Basic analysis: node centralities
• We will first extract the largest connected component and then compute the
node centrality measures
# Connected components are sorted in descending order of their size
cam_net_components = nx.connected_component_subgraphs(cam_net_ud)
cam_net_mc = cam_net_components[0]
# Betweenness centrality
bet_cen = nx.betweenness_centrality(cam_net_mc)
# Closeness centrality
clo_cen = nx.closeness_centrality(cam_net_mc)
# Eigenvector centrality
eig_cen = nx.eigenvector_centrality(cam_net_mc)
33
Basic analysis: most central nodes
• We first introduce a utility method: given a dictionary and a threshold parameter
K, the top K keys are returned according to the element values.
• We can then apply the method on the various centrality metrics available. Below
we extract the top 10 most central nodes for each case.
def get_top_keys(dictionary, top):
items = dictionary.items()
items.sort(reverse=True, key=lambda x: x[1])
return map(lambda x: x[0], items[:top])
top_bet_cen = get_top_keys(bet_cen,10)
Dostları ilə paylaş: