Relational neighbor 分類器
關係模型的基礎是節點之間的行為會互相關聯,也就是說彼此相連的節點傾向屬於同一個類別。特別是,relational neighbor 分類器會根據某節點的鄰近節點與相鄰邊來預測該節點的類別。
資料集 transfers 包含不同帳戶之間的交易。account_info 資料指出哪些帳戶是人頭帳戶(money mule)。然而,我們不知道帳戶 "I41" 是否為人頭帳戶。請使用 relational neighbor 分類器來預測帳戶 "I41" 成為人頭帳戶的傾向。
本練習屬於課程
R 的詐欺偵測
練習說明
- 建立一個以
transfers為基礎的「無向」圖,命名為net。將directed設為正確的布林值(TRUE或FALSE)。 - 為每個節點指定顏色:若
account_info$isMoneyMule == TRUE,將V(net)$color設為"darkorange",否則設為"slateblue1"。 - 在
net上使用subgraph()建立名為subset的子圖,包含節點"I41"、"I47"、"I87"與"I20"。 - 對
subnet「以及」net使用strength()函式,將節點"I41"的人頭帳戶機率計算為其人頭鄰居所佔的比例。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# From data frame to graph
net <- graph_from_data_frame(___, directed = ___)
# Plot the network; color nodes according to isMoneyMule-variable
___(___)$color <- ifelse(___$___ == TRUE, ___, ___)
plot(net, vertex.label.color = "black", vertex.label.font = 2, vertex.size = 18)
# The id's of the money mule accounts:
print(account_info$id[account_info$isMoneyMule == TRUE])
# Create subgraph containing node "I41" and all money mules nodes "I47", "I87", "I20":
subnet <- ___(___, v = c(___))
# Compute the money mule probability of node "I41" based on the neighbors
___(___, v = "I41") / ___(___, v = "I41")