始める無料で始める

学生プロジェクションの次数中心性分布を可視化する

この演習では、学生プロジェクションの次数中心性分布を可視化します。これは、これまでに学んだ「次数中心性」と「プロジェクション」という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() 
コードを編集して実行