找出重要的協作者
就要完成了!現在你會再看一次關鍵節點。這裡你會使用 NetworkX 的 degree_centrality() 與 betweenness_centrality() 來計算各自的中心性分數,然後利用這些資訊找出「重要的節點」。換句話說,你在本練習的任務是找出曾與最多使用者合作的使用者。
本練習屬於課程
Python 網路分析入門
練習說明
- 計算
G的度中心性。將結果儲存為deg_cent。 - 計算最大的度中心性。由於
deg_cent是字典,你需要先用.values()取得其值的清單,再用max()求出最大的度中心性。 - 使用串列生成式找出最活躍的協作者:
- 以
.items()迭代前面計算的度中心性字典deg_cent。如果你要找的是與最多使用者合作的使用者,應該滿足什麼條件?提示:與最大的度中心性有關。
- 以
- 按下「Submit Answer」來看看誰是最活躍的協作者!
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Compute the degree centralities of G: deg_cent
deg_cent = ____
# Compute the maximum degree centrality: max_dc
max_dc = ____
# Find the user(s) that have collaborated the most: prolific_collaborators
prolific_collaborators = [n for n, dc in ____ if ____ == ____]
# Print the most prolific collaborator(s)
print(prolific_collaborators)