네트워크 그래프 연결중심성, 매개중심성 계산
[네트워크 분석] 네트워크 중심성(Centrality) 지수 - 연결(Degree), 매개(Betweeness), 위세(Eigenvector), 근
안녕하세요. 중심성(Centrality) 지수에 대해서 정리해보려고 합니다. 1. 중심성(Centrality) 지수 중심...
blog.naver.com
https://theslaps.medium.com/centrality-metrics-via-networkx-python-e13e60ba2740
Centrality Metrics via NetworkX, Python
Zachary’s karate club is a widely used dataset [1] which originated from the paper “An Information Flow Model for Conflict and Fission in…
theslaps.medium.com
import networkx as nx
from networkx.readwrite import json_graph
import json
import matplotlib.pyplot as plt
import pandas as pd
G = nx.karate_club_graph()
print(type(G))
## #nodes: 34 and #edges: 78
print('#nodes:', len(G.nodes()), 'and', '#edges:', len(G.edges()))
with open('nodes.json', encoding='UTF8') as f:
json_data = json.loads(f.read())
G = nx.Graph()
for v in json_data:
G.add_node(v['id']) // nodes.json 파일 읽어서 networkx 노드로 추가
with open('links.json', encoding='UTF8') as f:
json_data = json.loads(f.read())
for v in json_data:
G.add_edge(v['source'],v['target']) // links.json 파일 읽어서 networkx 엣지로 추가
plt.figure(figsize=(40, 40))
nx.draw(G, with_labels=True)
plt.show()
degree_centrality=nx.degree_centrality(G)
eigenvector_centrality = nx.eigenvector_centrality(G)
closeness_centrality = nx.closeness_centrality(G)
betweenness_centrality = nx.betweenness_centrality(G)