Run Link Prediction or Node Classification Algorithms and Write Custom Procedures in C++ With Mage 1.4

by
Antonio Filipovic
Run Link Prediction or Node Classification Algorithms and Write Custom Procedures in C++ With Mage 1.4

In the new release of Memgraph’s open-source graph extension library MAGE, we focused on supporting graph machine learning. MAGE 1.4 now enables you to classify graph nodes and predict new relationships using the node classification and link prediction algorithms.

We also wanted to extend MAGE towards the C++ community even more and created the C++ API towards Memgraph database. Writing graph algorithms in C++ now comes close to working in Python since you don’t need to worry about handling memory and working with unnecessary interfaces.

If you are also familiar with igraph library, you’ll be happy to hear that we integrated it into MAGE, and the newly integrated k-means algorithm will help you cluster your data.

Link prediction

Link prediction tries to predict new relationships by generalizing on unseen nodes at inference time. Inside the module, you can choose to work on link prediction using GraphSAGE or GAT. The module was integrated using DGL implementation, and it supports a lot of different logging metrics, as well as storing models after a certain number of epochs.

One example of what you can do with the link prediction algorithm is to recommend new services for customers by using a query similar to this one:

MATCH (n:Customer {id: "1658"})
MATCH (s:Service)
WITH collect(s) AS services, n
CALL link_prediction.recommended_vertex(n, services, 6) YIELD *
RETURN score, recommendation;

Node classification

Node classification determines the labeling of samples (represented as nodes) by looking at the labels of their neighbors. It is motivated by homophily, which means "love of sameness” based on the sociological theory that similar things will group. The following module supports different layer types, loading and storing models, and much more.

With node classification, you can work on fraud prediction by using a query like the one below to determine if a certain user is a fraudster or not:

MATCH (n {id:1658}) 
CALL node_classification.predict(n) YIELD * 
RETURN predicted_class;

C++ API designed for humans

The new C++ API is designed for humans, not robots. We followed best practices to reduce unnecessary cognitive load: the components have simple and consistent interfaces, common use cases require fewer user actions, and the API comes with developer guides and extensive documentation.

Memory management is probably the main pain point in C++ development. The new C++ API automatically manages the memory used by graph data, saving you time that would otherwise be spent debugging and writing repetitive code.

igraph support is here

Furthermore, the igraphalg module provides a comprehensive set of thin wrappers around some of the algorithms present in the igraph package. The wrapper functions can create an igraph-compatible graph-like object that can stream the native database graph directly, significantly lowering memory usage.

From this version, MAGE supports NetworkX integration, cuGraph to support graph algorithms on CUDA devices, and now igraph. Whether you need something else, feel free to drop us a comment on GitHub.

k-means clustering to group examples

And last but not least, the k-means algorithm clusters given data by trying to separate samples in n groups of equal variance by minimizing the criterion known as within-the-cluster sum-of-squares. Find out more about this algorithm in the documentation,

You can use this algorithm when you already have embeddings, but clustering is missing. For example, feel free to combine it with Node2Vec or Node2Vec online version.

What next?

If any of the new features are the one that will make your use case easier, update MAGE to version 1.4. Feel free to leave a comment, report an issue or give us a star as support for our work on GitHub. Also, we are always open for discussions and advice, drop them on our Discord Server and stay informed on everything graph-algorithm-related!

Table of Contents

Get a personalized Memgraph demo
and get your questions answered.

Continue Reading

synchronize-data-between-memgraph-graph-database-and-elasticsearch
Showcase
Dev Tools
Under the Hood
Memgraph MAGE
Synchronize Data Between Memgraph Graph Database and Elasticsearch

If you need to reap the benefits of both a graph database and Elasticsearch, the new module in Memgraph’s graph library MAGE enables you to easily synchronize those two components using triggers.

by
Andi Skrgat
February 3, 2023
new-memgraph-platform-for-another-year-of-high-performance-graph-analysis
Product
Announcements
New Memgraph Platform for Another Year of High Performance Graph Analysis

Start next year with a whole new range of features and graph algorithms to gain insights that will make it a happy year indeed! Developed features include improved security, benchmark tests, projected graph visualization, better code suggestion support, C++ API, node classification and link prediction, to name just a few.

by
Marko Budiselic
December 13, 2022
become-an-inspector-for-a-day-and-detect-fraudsters-with-graph-ml-on-memgraph
Machine Learning
Fraud Detection
Use Cases
Graph Algorithms
Become an Inspector for a Day and Detect Fraudsters With Graph ML on Memgraph!

This blog post deals with solving fraud detection problems with graph machine learning. Learn how to load data, training and plot to find out who did it! It’s elementary, my dear reader.

by
Mateo Dujic
December 7, 2022