為節點加上標籤
在這個練習中,你要為網路中的節點加上標籤。你會拿到一個名為 customers 的 dataframe,其中的客戶 ID 與網路中的相同。每位客戶都有是否流失的標示,分別以 1 或 0 表示。
你將把流失狀態加入到網路的節點上,並加以視覺化。
請注意,網路可以同時具有「節點」與「邊」屬性。
「節點」屬性以 V()(vertex)函式表示,而「邊」屬性以 E() 函式表示。
流失網路的節點屬性為 V(network)。
本練習屬於課程
使用 R 進行網路化資料的預測分析
練習說明
- 使用
head()函式檢視customersdataframe。 - 使用
table()函式統計customersdataframe 中流失與未流失客戶的數量。 - 使用
V()函式在網路中新增名為churn的節點屬性,並指定為customersdataframe 的churn欄位。 - 呼叫
plot()函式視覺化此網路。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Inspect the customers dataframe
___(customers)
# Count the number of churners and non-churners
table(customers$___)
# Add a node attribute called churn
___(network)$___ <- customers$churn
# Visualize the network
___(___, vertex.label = NA, edge.label = NA,
edge.color = 'black', vertex.size = 2)