การกระจาย degree centrality ของโหนดโปรเจกต์
ถึงเวลาพล็อตการกระจาย degree centrality ของพาร์ติชัน 'projects' ใน G แล้ว ขั้นตอนเหมือนกับแบบฝึกหัดก่อนหน้าทุกประการ และ matplotlib.pyplot ได้ถูกนำเข้าไว้ล่วงหน้าในชื่อ plt แล้ว
ลองทำดูได้เลย!
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การวิเคราะห์เครือข่ายระดับกลางใน Python
คำแนะนำการฝึกหัด
- สร้างลิสต์ชื่อ
project_nodesที่เก็บโหนดในพาร์ติชัน'projects'ของG - ใช้ฟังก์ชัน
nx.degree_centrality()คำนวณค่า degree centrality ของแต่ละโหนดในGแล้วเก็บผลลัพธ์ไว้ในตัวแปรdcs - ใช้ list comprehension คำนวณค่า degree centrality ของแต่ละโหนดใน
project_nodesแล้วเก็บผลลัพธ์ไว้ในตัวแปรproject_dcs - พล็อตฮิสโทแกรมของการกระจาย degree ของโปรเจกต์ โดยใช้
plt.hist()กับproject_dcs
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Get the 'projects' nodes: project_nodes
project_nodes = ____
# Compute the degree centralities: dcs
dcs = ____
# Get the degree centralities for project_nodes: project_dcs
project_dcs = [____]
# Plot the degree distribution of project_dcs
plt.yscale('log')
plt.hist(____, bins=20)
plt.show()