学生プロジェクションの次数中心性分布を可視化する
この演習では、学生プロジェクションの次数中心性分布を可視化します。これは、これまでに学んだ「次数中心性」と「プロジェクション」という2つの概念の復習です。
この演習はコースの一部です
Python 中級ネットワーク解析
演習の手順
'student'パーティションのノードをstudent_nodesというリストに取得します。- これにはリスト内包表記を使い、
Gのすべてのノード(メタデータを含む)を走査して、dの'bipartite'キーワードが'student'に等しいかを確認します。
- これにはリスト内包表記を使い、
- 学生ノードのプロジェクションを
G_studentsというグラフとして作成します。nx.bipartite.projected_graph()関数を使い、キーワード引数nodes=student_nodesを必ず指定します。 nx.degree_centrality()を使ってG_studentsの次数中心性を計算し、結果をdcsに保存します。- 次数中心性の値のヒストグラムをプロットします。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Import necessary modules
import matplotlib.pyplot as plt
import networkx as nx
# Get the student partition's nodes: student_nodes
student_nodes = [n for n, d in ____ if d['____'] == '____']
# Create the students nodes projection as a graph: G_students
G_students = ____
# Calculate the degree centrality using nx.degree_centrality: dcs
dcs = ____
# Plot the histogram of degree centrality values
plt.hist(list(____))
plt.yscale('log')
plt.show()