You are the mean of all your peers
Identifying fraudsters & terrorists using graph databases ; )
Let’s look at A graph containing vertices (persons) and edges (interactions, i.e. call or text) which might look like:
Having loaded the graph into a graph database like neo4j allows for easy queries of the social network of a :Person. To check the network for hidden terrorists, I select other nodes which are up to 3 edges away from the original node and calculate the fraudulence as the average of all its neighbours , i.e. their interactions:
which will give the following result:
Interestingly, David seems to be the one best connected to the terrorsts/fraudsters.
When breaking down the fraudulence by type of relationship:call|text as separate features this can easily be achieved by the following code snippet. It might look a bit intimidating, but is used to get a more efficient query plan. Instead of reading the graph twice, a single pass over the data is enough (https://stackoverflow.com/questions/47617655/neo4j-single-pass-over-graph-but-multiple-matches)
which results in:
The following jupyter notebook outlines how to use python to get a couple more alternate variants of this query (variations of depth and direction) https://github.com/geoHeil/graph-playground/blob/master/neo4j.ipynb and finally reshape the results.
Get Georg Heiler’s stories in your inbox
Join Medium for free to get updates from this writer.
For a small graph neo4j is a great tool — but assuming the data is larger a different tool is requried. There, hadoop comes into play. Spark offers some graph computation capabilities on Hadoop. The graphFrames package contains a subset of cypher patterns which ease the adoption of graph tasks in the distributed context of Hadoop.
The CSV files are read directly into spark. Then, the graphFrames library is used to resolve the cypher pattern.
NOTE: currently the cypher patterns supported are rather minimal! Also scalability is questionable as the patterns are resolved using JOINS and not using an BSP iterative operator. https://stackoverflow.com/questions/41351802/partitioning-with-spark-graphframes
For this minimal dataset at least broadcast hash joins can be used (i.e. map side join)
Also, aggregations need to be performed outside of the graph processing library, i.e. in this case in plain spark:
Computing any of the combined queris as before gets a bit laborious as only few cypher patterns are supported out of the box. Here I build the [*1..3]by hand:
A lot is happening in the space of distributed graph analytics. Neo4j is pushing spark support within the opencypher project. Recently, https://github.com/opencypher/cypher-for-apache-spark was released — still in the alpha stage it CAPS will bring more comprehensive support for cypher queries on spark.
All the code can be found on github: https://github.com/geoHeil/graph-playground





