Skip to main content

Command Palette

Search for a command to run...

DPS-Prac5

DPS-Prac5

Published
•2 min read•View as Markdown
Senario 1: You are investigating a money transfer network to detect suspicious behavior. You suspect
one account (A6) to be fraudulent due to multiple high-value transfers.

CREATE
  (p1:Person {id:'P1', name:'Alice'}),
  (p2:Person {id:'P2', name:'Bob'}),
  (p3:Person {id:'P3', name:'Charlie'}),
  (p4:Person {id:'P4', name:'David'}),
  (p5:Person {id:'P5', name:'Esha'}),
  (p6:Person {id:'P6', name:'SuspiciousUser'}),

  (c1:Company {id:'C1', name:'XCorp'}),
  (c2:Company {id:'C2', name:'YTech'}),

  (a1:Account {id:'A1'}), (a2:Account {id:'A2'}), (a3:Account {id:'A3'}),
  (a4:Account {id:'A4'}), (a5:Account {id:'A5'}), (a6:Account {id:'A6'}),

  (p1)-[:OWNS]->(a1), (p2)-[:OWNS]->(a2), (p3)-[:OWNS]->(a3),
  (p4)-[:OWNS]->(a4), (p5)-[:OWNS]->(a5), (p6)-[:OWNS]->(a6),

  (p1)-[:WORKS_FOR]->(c1), (p6)-[:WORKS_FOR]->(c2),

  (a1)-[:TRANSFERRED {amount: 3000}]->(a2),
  (a2)-[:TRANSFERRED {amount: 4000}]->(a3),
  (a3)-[:TRANSFERRED {amount: 5000}]->(a4),

  (a6)-[:TRANSFERRED {amount: 95000}]->(a1),
  (a6)-[:TRANSFERRED {amount: 89000}]->(a3),
  (a6)-[:TRANSFERRED {amount: 102000}]->(a5);


CALL gds.graph.project(
 'fraud-graph',
 ['Account'],
 {
 TRANSFERRED: {
 type: 'TRANSFERRED',
 orientation: 'NATURAL',
 properties: ['amount']
 }
 }
);


CALL gds.pageRank.stream('fraud-graph')
YIELD nodeId, score
RETURN gds.util.asNode(nodeId).id AS account, score
ORDER BY score DESC;


CALL gds.betweenness.stream('fraud-graph')
YIELD nodeId, score
RETURN gds.util.asNode(nodeId).id AS account, score
ORDER BY score DESC;


CALL gds.louvain.write('fraud-graph', {writeProperty: 'communityId'})
YIELD communityCount;
MATCH (a:Account)
RETURN a.id, a.communityId
ORDER BY a.communityId;


CALL gds.nodeSimilarity.stream('fraud-graph')
YIELD node1, node2, similarity
RETURN gds.util.asNode(node1).id AS account1,
 gds.util.asNode(node2).id AS account2,
 similarity
ORDER BY similarity DESC
LIMIT 10;


MATCH path = (a:Account {id: 'A6'})-[:TRANSFERRED*2..5]->(b:Account)
RETURN path
LIMIT 5;


MATCH (a:Account)-[:TRANSFERRED]->()
WITH a, count(*) AS outDegree
WHERE outDegree > 2
RETURN a.id, outDegree;


MATCH (a:Account)<-[t:TRANSFERRED]-()
WITH a, sum(t.amount) AS totalIn
WHERE totalIn > 100000
RETURN a.id, totalIn;


Dataset 1: Money Flow Network

UNWIND range(1, 50) AS i
CREATE (:User {id: 'U' + i, name: 'User' + i});

UNWIND range(1, 45) AS i
MATCH (u1:User {id: 'U' + i}), (u2:User {id: 'U' + (i + 1)})
CREATE (u1)-[:TRANSFERRED {amount: toInteger(rand()*4000 + 1000)}]->(u2);

MATCH (fraud:User {id: 'U50'})
UNWIND [1,5,10,15,20,25,30,35,40,45] AS i
MATCH (target:User {id: 'U' + i})
CREATE (fraud)-[:TRANSFERRED {amount: toInteger(rand()*50000 + 50000)}]->(target);