Using Neo4j Graph Data Science in Python to Improve Machine Learning Models

Utilize graph algorithms in the Neo4j Graph Data Science library to extract graph-based features and improve the accuracy of machine learning models

Graph schema of the P2P payment platform. Image by the author.
A sample of P2P network. Image by the author.

Prepare the Neo4j environment

Install APOC and GDS plugins. Image by the author.

Neo4j Graph Data Science Python client

pip install graphdatascience

Exploring the dataset

Count of transactions per year. Image by the author.
Results of the describe method. Image by the author.
Correlation matrix. Image by the author

Training a baseline classification model

Baseline model confusion matrix. Image by the author.
Baseline model ROC curve. Image by the author.

Using graph-based features to increase the accuracy of the model

P2P transaction network. Image by the author.
Network of users and devices they used. Image by the author.
'P2P':{       
'type':'P2P',
'properties':{
'totalAmount':{
'aggregation':'SUM'
}
}
}
Merge parallel relationships and sum their properties. Image by the author.
An example network where two weakly-connected components are present. Image by the author.
An example network where four users used the same credit card. Image by the author.
Results of the WCC algorithm. Image by the author.
An example network where nodes are colored based on their PageRank score. Image by the author.
An example network where nodes are colored based on their Closeness centrality score. Image by the author.

Combine baseline and graph features

Include the graph-based features in the classification model

Confusion matrix of the model that includes graph-based features. Image by the author.
ROC curve of the model that includes graph-based features. Image by the author.

Conclusion

References

--

--

Developer Content around Graph Databases, Neo4j, Cypher, Data Science, Graph Analytics, GraphQL and more.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Tomaz Bratanic

Data explorer. Turn everything into a graph. Author of Graph algorithms for Data Science at Manning publication.