次数中心性の分布
ノードの次数は、そのノードが持つ隣接ノードの数です。次数中心性は、隣接ノードの数を、取り得るすべての隣接ノードの数で割った値です。自己ループを許すかどうかによって、取り得る隣接ノードの集合には、そのノード自身が含まれる場合もあります。
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()