1 / 7

Centrality – Python - NetworkX

Centrality – Python - NetworkX. Degree Centrality. Degree Centrality – Find the “Celebrities” Figure 1.1 Network >>> degree_centrality = net.degree_centrality(g) >>> degree_centrality {1: 0.375, 2: 0.25, 3: 0.375, 4: 0.5, 5: 0.5, 6: 0.5, 7: 0.5, 8: 0.375, 9: 0.125}

lpina
Télécharger la présentation

Centrality – Python - NetworkX

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Centrality – Python - NetworkX LINK@KOREATECH

  2. Degree Centrality • Degree Centrality – Find the “Celebrities” • Figure 1.1 Network • >>> degree_centrality = net.degree_centrality(g) • >>> degree_centrality • {1: 0.375, 2: 0.25, 3: 0.375, 4: 0.5, 5: 0.5, 6: 0.5, 7: 0.5, 8: 0.375, 9: 0.125} • Definesort_map funtion • Sort the degree centrality • >>> import sort_map • >>> sorted_degree_centrality = sort_map.sort_map(degree_centrality) • >>> sorted_degree_centrality • [(4, 0.5), (5, 0.5), (6, 0.5), (7, 0.5), (1, 0.375), (3, 0.375), (8, 0.375), (2, 0.25), (9, 0.125)] sort_map.py • import operator • def sort_map(map): • sortedList = map.items() • sortedList.sort(key=operator.itemgetter(1), reverse=True) • return sortedList LINK@KOREATECH

  3. Closeness Centrality • Closeness Centrality - Find the Gossipmongers • Figure 1.1 Network • >>> closeness_centrality = net.closeness_centrality(g) • >>> closeness_centrality • {1: 0.47058823529411764, 2: 0.34782608695652173, 3: 0.47058823529411764, 4: 0.6153846153846154, 5: 0.6153846153846154, 6: 0.6153846153846154, 7: 0.5,8: 0.47058823529411764, 9: 0.34782608695652173} • >>> import sort_map • >>> sorted_closeness_centrality = sort_map.sort_map(closeness_centrality) • >>> sorted_closeness_centrality • [(4, 0.6153846153846154), (5, 0.6153846153846154), (6, 0.6153846153846154), (7, 0.5), (1, 0.47058823529411764), (3, 0.47058823529411764), (8, 0.47058823529411764), (2, 0.34782608695652173), (9, 0.34782608695652173)] LINK@KOREATECH

  4. Betweenness Centrality • Betweenness Centrality - Find the Communication Bottlenecks and/or Community Bridges • Figure 1.1 Network • >>> bet_centrality = net.betweenness_centrality(g) • >>> bet_centrality • {1: 0.10714285714285714, 2: 0.0, 3: 0.10714285714285714, 4: 0.5357142857142857, 5: 0.21428571428571427, 6: 0.21428571428571427, 7: 0.25, 8: 0.0, 9: 0.0} • >>> import sort_map • >>> sorted_bet_centrality = sort_map.sort_map(bet_centrality) • >>> sorted_bet_centrality • [(4, 0.5357142857142857), (7, 0.25), (5, 0.21428571428571427), (6, 0.21428571428571427), (1, 0.10714285714285714), (3, 0.10714285714285714), (2, 0.0), (8, 0.0), (9, 0.0)] LINK@KOREATECH

  5. Eigenvector Centrality • Eigenvector Centrality • Figure 1.1 Network • >>> eigenvector_centrality = net. eigenvector_centrality(g) • >>> eigenvector_centrality • {1: 0.1957517982158921, 2: 0.11168619729756277, 3: 0.1957517982158921, 4: 0.3787497778502688, 5: 0.4680845766467969, 6: 0.4680845766467969, 7: 0.4099777873648637, 8: 0.3840189757284676, 9: 0.11695539517576158} • >>> import sort_map • >>> sorted_eigenvector_centrality = sort_map.sort_map(eigenvector_centrality) • >>> sorted_eigenvector_centrality • [(5, 0.4680845766467969), (6, 0.4680845766467969), (7, 0.4099777873648637), (8, 0.3840189757284676), (4, 0.3787497778502688), (1, 0.1957517982158921), (3, 0.1957517982158921), (9, 0.11695539517576158), (2, 0.11168619729756277)] LINK@KOREATECH

  6. Putting It Together • Adjust the values • Values Rounded • >>> rounded_degree_centrality = {k: round(v, 3) for k, v in degree_centrality.items()} • >>> rounded_closeness_centrality = {k: round(v, 3) for k, v in closeness_centrality.items()} • >>> rounded_bet_centrality = {k: round(v, 3) for k, v in bet_centrality.items()} • >>> rounded_eigenvector_centrality = {k: round(v, 3) for k, v in eigenvector_centrality.items()} • Build a table with four centralities • Making some conclusions about the figure 1.1 • >>> table = [[node, rounded_degree_centrality[node], rounded_closeness_centrality[node], rounded_bet_centrality[node], rounded_eigenvector_centrality[node]] for node in g.nodes()] LINK@KOREATECH

  7. Putting It Together • Build a table with four centralities LINK@KOREATECH

More Related