การกระจาย Degree Centrality
Degree ของโหนดคือจำนวนเพื่อนบ้านที่โหนดนั้นมี ส่วน degree centrality คือจำนวนเพื่อนบ้านหารด้วยจำนวนเพื่อนบ้านที่เป็นไปได้ทั้งหมด ทั้งนี้ขึ้นอยู่กับว่าอนุญาตให้มี self-loop หรือไม่ ซึ่งอาจรวมตัวโหนดเองด้วย
ฟังก์ชัน nx.degree_centrality(G) จะคืนค่าเป็น dictionary โดยมีโหนดเป็น key และค่า degree centrality เป็น value
การกระจาย degree ที่ชื่อว่า degrees ซึ่งคำนวณไว้ในแบบฝึกหัดก่อนหน้าโดยใช้ list comprehension ได้ถูกโหลดไว้ให้แล้ว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การวิเคราะห์เครือข่ายเบื้องต้นด้วย Python
คำแนะนำการฝึกหัด
- คำนวณ degree centrality ของเครือข่าย Twitter
T - ใช้
plt.hist()พล็อตฮิสโตแกรมของการกระจาย degree centrality ของTโดยเข้าถึงข้อมูลนี้ได้ผ่านlist(deg_cent.values()) - พล็อตฮิสโตแกรมของการกระจาย degree ที่ชื่อว่า
degreesของTซึ่งเป็น list เดิมที่คำนวณไว้ในแบบฝึกหัดที่แล้ว - สร้าง scatter plot โดยให้
degreesอยู่บนแกน x และการกระจาย degree centralitylist(deg_cent.values())อยู่บนแกน y
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# 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()