แสดงการกระจายของ degree centrality ใน forums projection
แบบฝึกหัดนี้ช่วยทบทวนแนวคิดเรื่อง degree centrality และ projection อีกครั้ง คราวนี้จะพล็อตการกระจายของ degree centrality สำหรับ 'forum' projection ทำตามขั้นตอนเดียวกับแบบฝึกหัดที่แล้วได้เลย
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การวิเคราะห์เครือข่ายระดับกลางใน Python
คำแนะนำการฝึกหัด
- ดึง node ของ partition
'forum'มาเก็บในลิสต์ชื่อforum_nodes - สร้าง forums nodes projection เป็นกราฟชื่อ
G_forum - คำนวณ degree centrality ของ
G_forumโดยใช้nx.degree_centrality()แล้วเก็บผลลัพธ์ไว้ในdcs - พล็อตฮิสโตแกรมของค่า degree centrality
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Import necessary modules
import matplotlib.pyplot as plt
import networkx as nx
# Get the forums partition's nodes: forum_nodes
forum_nodes = [____]
# Create the forum nodes projection as a graph: G_forum
G_forum = ____
# Calculate the degree centrality using nx.degree_centrality: dcs
dcs = ____
# Plot the histogram of degree centrality values
____
plt.yscale('log')
plt.show()