Get startedGet started for free

Relational neighbor classifier

A relation model is based on the idea that the behavior between nodes is correlated, meaning that connected nodes have a propensity to belong to the same class. The relational neighbor classifier, in particular, predicts a node's class based on its neighboring nodes and adjacent edges.

The dataset transfers consists of transactions from different accounts. The account_info data contains which of these accounts are money mules. However, it is unknown whether account "I41" is a money mule. Predict the money mule propensity of account "I41" using a relational neighbor classifier.

This exercise is part of the course

Fraud Detection in R

View Course

Exercise instructions

  • Create an undirected graph called net based on transfers. Set directed to the appropriate boolean (TRUE or FALSE).
  • Specify a color for each node: set V(net)$color to "darkorange" if account_info$isMoneyMule == TRUE and "slateblue1" otherwise.
  • Use subgraph() on net to create a subgraph called subset containing vertices "I41","I47", "I87" and "I20".
  • Use function strength() on subnet and on net to compute the money mule probability of node "I41" as the fraction of mule neighbors

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# 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")
Edit and Run Code