度中心性分布
節點的度數是它擁有的鄰居數量。度中心性是鄰居數量除以所有可能鄰居數量。根據是否允許自我迴圈(self-loop),節點可擁有的可能鄰居集合也可能包含它自己。
nx.degree_centrality(G) 會回傳一個字典,鍵為節點,值為其度中心性。
你在上一個練習中用列表生成式計算出的度分布 degrees 已經預先載入。
本練習屬於課程
Python 網路分析入門
練習說明
- 計算 Twitter 網路
T的度中心性。 - 使用
plt.hist()繪製T的度中心性分布直方圖。可使用list(deg_cent.values())取得。 - 繪製
T的度分布degrees的直方圖。這與你在上一個練習中計算的列表相同。 - 建立散佈圖,將
degrees放在 x 軸、將度中心性分布list(deg_cent.values())放在 y 軸。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# 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()