พล็อตการกระจาย Degree Centrality บน Projection
ในแบบฝึกหัดนี้ เราจะเปรียบเทียบการกระจายของค่า degree centrality จากกราฟทั้งสามแบบ ได้แก่ กราฟต้นฉบับ G, กราฟ projection ของกลุ่มคน peopleG และกราฟ projection ของกลุ่มชมรม clubsG เพื่อให้เห็นความแตกต่างในการคำนวณค่า degree centrality ระหว่างกราฟแบบ bipartite และ unipartite ได้ชัดเจนยิ่งขึ้น โดย node list ของ people และ clubs ถูกโหลดไว้ให้แล้ว
จำไว้ว่าฟังก์ชันใน bipartite module จำเป็นต้องรับ container ของ node เป็นอาร์กิวเมนต์ แต่จะคืนค่า degree centrality ของทุก node กลับมาเสมอ และค่า degree centrality จะถูกเก็บในรูปแบบ dictionary (mapping จาก node ไปยังค่าคะแนน)
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การวิเคราะห์เครือข่ายระดับกลางใน Python
คำแนะนำการฝึกหัด
- พล็อตการกระจายของค่า degree centrality ของกราฟต้นฉบับ
Gโดยใช้ฟังก์ชันdegree_centralityจาก bipartite module:nx.bipartite.degree_centrality()ซึ่งรับอาร์กิวเมนต์ 2 ตัว คือ กราฟGและ node list ใดตัวหนึ่ง (peopleหรือclubs) - พล็อตการกระจายของค่า degree centrality ของกราฟ
peopleGโดยใช้ฟังก์ชันdegree_centralityแบบปกติ (non-bipartite) จาก NetworkX:nx.degree_centrality() - พล็อตการกระจายของค่า degree centrality ของกราฟ
clubsGโดยใช้ฟังก์ชันdegree_centralityแบบปกติ (non-bipartite) จาก NetworkX:nx.degree_centrality()
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
import matplotlib.pyplot as plt
# Plot the degree centrality distribution of both node partitions from the original graph
plt.figure()
original_dc = ____
# Remember that you can directly plot dictionary values.
plt.hist(____, alpha=0.5)
plt.yscale('log')
plt.title('Bipartite degree centrality')
plt.show()
# Plot the degree centrality distribution of the peopleG graph
plt.figure()
people_dc = ____
plt.hist(____)
plt.yscale('log')
plt.title('Degree centrality of people partition')
plt.show()
# Plot the degree centrality distribution of the clubsG graph
plt.figure()
clubs_dc = ____
plt.hist(____)
plt.yscale('log')
plt.title('Degree centrality of clubs partition')
plt.show()