寻找重要协作者
就差最后一步!现在再次关注重要节点。这里,您将使用 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)