统计节点并计算连通度
在本练习中,您将使用 customers 数据框统计每种类型的节点数量。churn 列有两个取值:
- 0 表示未流失客户
- 1 表示流失客户
您还将使用公式 \(p=\frac{2E}{N(N-1)}\) 计算网络的连通度,其中 \(N\) 为网络中的节点数,\(E\) 为边数。
本练习是课程的一部分
使用 R 进行网络数据的预测分析
练习说明
- 通过条件筛选
customers$churn统计流失节点的数量。 - 通过条件筛选
customers$churn统计未流失节点的数量。 - 统计节点总数,并将变量命名为
nodes。 - 使用上面给出的 \(p\) 的公式计算网络的连通度。您可以复用上一个练习中的
edges。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Count the number of churn nodes
ChurnNodes <- sum(customers$___ == ___)
# Count the number of non-churn nodes
NonChurnNodes <- sum(___)
# Count the total number of nodes
___ <- ChurnNodes + NonChurnNodes
# Compute the network connectance
connectance <- 2 * ___ / ___ / (nodes - 1)
# Print the value
connectance