度中心性分布
一个节点的度是它拥有的邻居数量。度中心性是该邻居数量除以它可能拥有的所有邻居数量。根据是否允许自环,节点可能拥有的邻居集合也可能包含节点自身。
函数 nx.degree_centrality(G) 返回一个字典,键是节点,值是对应的度中心性值。
您在上一个练习中使用列表推导式计算的度分布 degrees 已预先加载。
本练习是课程的一部分
Python 网络分析入门
练习说明
- 计算 Twitter 网络
T的度中心性。 - 使用
plt.hist()绘制度中心性分布的直方图,可通过list(deg_cent.values())获取。 - 绘制
T的度分布degrees的直方图。这与您在上一个练习中计算的列表相同。 - 创建一个散点图,x 轴为
degrees,y 轴为度中心性分布list(deg_cent.values())。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# 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()