เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

พล็อตการกระจาย 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()
แก้ไขและรันโค้ด