在網路中找出同質性
節點通常會帶有其相關的特徵或屬性。資料框 account_info 包含每個帳戶的型態。同質性(homophily)是社會學中的一個概念。在詐欺網路中,同質性表示詐欺者更可能與其他詐欺者相連,而合法使用者更可能與其他合法使用者相連。根據商業情境與詐欺類型,同質性可能存在也可能不存在。讓我們根據屬性 account_type 來檢查網路中的同質性。
你可以用 V(my_network)$new_node_attribute 把屬性加到網路的節點上。
igraph 套件與上一個練習中的網路 net 已載入到你的工作環境中。
本練習屬於課程
R 的詐欺偵測
練習說明
- 將
account_info中的變數type作為屬性account_type加到網路net的節點上。 - 印出
net的頂點屬性。 - 由於
account_type是名目變數,請使用assortativity_nominal,根據account_type檢查網路中的同質性。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Add account_type as an attribute to the nodes of the network
___(net)$___ <- ___$___
# Have a look at the vertex attributes
print(___(___))
# Check for homophily based on account_type
___(___, types = ___, directed = FALSE)