開始使用免費開始

為節點加上標籤

在這個練習中,你要為網路中的節點加上標籤。你會拿到一個名為 customers 的 dataframe,其中的客戶 ID 與網路中的相同。每位客戶都有是否流失的標示,分別以 1 或 0 表示。 你將把流失狀態加入到網路的節點上,並加以視覺化。

請注意,網路可以同時具有「節點」與「邊」屬性。 「節點」屬性以 V()(vertex)函式表示,而「邊」屬性以 E() 函式表示。 流失網路的節點屬性為 V(network)

本練習屬於課程

使用 R 進行網路化資料的預測分析

檢視課程

練習說明

  • 使用 head() 函式檢視 customers dataframe。
  • 使用 table() 函式統計 customers dataframe 中流失與未流失客戶的數量。
  • 使用 V() 函式在網路中新增名為 churn 的節點屬性,並指定為 customers dataframe 的 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)
編輯並執行程式碼