計算節點數與連通率
在這個練習中,你會用 customers 資料框來計算各類型節點的數量。churn 欄位有兩種數值:
- 0:未退訂
- 1:已退訂
你也會使用公式 \(p=\frac{2E}{N(N-1)}\) 計算網路的連通率(connectance),其中 \(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