開始使用免費開始

擷取邊的型別

在這個練習中,你會把客戶資料框的客戶 ID 與客戶邊列表進行配對,判斷每一條邊是流失(churn)、非流失,或是混合邊。 使用 match() 函式,為邊列表新增兩個欄位。

  1. fromLabelfrom 欄位節點的流失標籤
  2. toLabelto 欄位節點的流失標籤

指令 match(x, y) 會回傳一個向量,表示 xy 中的位置。上圖中,match(edgeList$from, customers$id) 的結果是 1,1,1,2,2。例如,edgeList$from 的第 4 列(ID 為 393 的客戶)是 customers$id 的第 2 個元素。 因此,這位客戶的流失標籤是 customers[2,2],也就是 0。 同理,edgeList$from 中每位客戶的流失標籤為 customers[match(edgeList$from, customers$id),2]

本練習屬於課程

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

檢視課程

練習說明

  • edgeList 資料框中新增名為 FromLabel 的欄位,做法是將 edgeList$fromcustomers$id 配對後,擷取 customers$churn 作為 from 節點的標籤。
  • to 邊也做相同的事,並將欄位命名為 ToLabel
  • edgeList 資料框中新增名為 edgeType 的欄位,內容為 FromLabelToLabel 兩欄的和。
  • 使用 table() 函式查看各種邊型別的數量。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Add the column edgeList$FromLabel
edgeList$FromLabel <- customers[match(edgeList$___, customers$___), 2]
 
# Add the column edgeList$ToLabel
edgeList$ToLabel <- customers[___(___, ___), 2]
 
# Add the column edgeList$edgeType
edgeList$edgeType <- edgeList$___ + edgeList$___
 
# Count the number of each type of edge
___(edgeList$edgeType)
編輯並執行程式碼