차수 중심성 분포
노드의 차수(degree)는 그 노드가 가진 이웃의 수를 뜻합니다. 차수 중심성(degree centrality)은 이웃의 수를 그 노드가 가질 수 있는 모든 가능한 이웃 수로 나눈 값입니다. 자기 루프(self-loop)를 허용하는지에 따라, 노드가 가질 수 있는 가능한 이웃의 집합에는 그 노드 자신이 포함될 수도 있습니다.
nx.degree_centrality(G) 함수는 딕셔너리를 반환하며, 키는 노드이고 값은 해당 노드의 차수 중심성 값입니다.
이전 연습 문제에서 리스트 컴프리헨션으로 계산한 차수 분포 degrees는 미리 로드되어 있습니다.
이 연습은 강의의 일부입니다
Python으로 시작하는 네트워크 분석
연습 안내
- Twitter 네트워크
T의 차수 중심성을 계산하세요. plt.hist()를 사용해T의 차수 중심성 분포 히스토그램을 그리세요.list(deg_cent.values())로 접근할 수 있습니다.T의 차수 분포degrees에 대한 히스토그램을 그리세요. 이는 이전 연습 문제에서 계산한 동일한 리스트입니다.- x축에는
degrees, y축에는 차수 중심성 분포list(deg_cent.values())를 두고 산점도를 만드세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Import matplotlib.pyplot
import matplotlib.pyplot as plt
# Compute the degree centrality of the Twitter network: deg_cent
deg_cent = ____
# Plot a histogram of the degree centrality distribution of the graph.
plt.figure()
____
plt.show()
# Plot a histogram of the degree distribution of the graph
plt.figure()
____
plt.show()
# Plot a scatter plot of the centrality distribution and the degree distribution
plt.figure()
____
plt.show()