# Machine learning

Memgraph has been a popular choice in the AI world for a while now, especially
for the use cases around machine learning (ML). The MAGE library aims to provide
the most commonly used graph algorithms, and that includes [graph ML
algorithms](https://memgraph.com/docs/advanced-algorithms/available-algorithms#graph-ml-algorithms) as
well. 

## Node embeddings

Supervised machine learning is a subset of ML where algorithms try to learn from
data. Modeling the interactions between entities as graphs has enabled
researchers to understand the various networks systematically. For the computer
to understand these networks, embedding a large graph in low dimensional space
is necessary, creating node embeddings. It has been demonstrated that graph
embedding is superior to alternatives in many supervised learning tasks, such as
**node classification** and **link prediction**, which are usually used for
friendship or content recommendations and advertisement.

#### Algorithms
 

Here are the MAGE algorithms which create node embeddings:
- [node2vec](https://memgraph.com/docs/advanced-algorithms/available-algorithms/node2vec): An algorithm
  for calculating node embeddings on a static graph.
- [node2vec_online](https://memgraph.com/docs/advanced-algorithms/available-algorithms/node2vec_online):
  An algorithm for calculating node embeddings on a dynamic graph.

#### Resources
 

In case you'd like to learn more about the topic and see
practical examples, check out the following resources:
- [Introduction to Node
  Embedding](https://memgraph.com/blog/introduction-to-node-embedding): A blog
  post covering the basics of node embeddings. 
- [How Node2Vec Works – A Random Walk-Based Node Embedding
  Method](https://memgraph.com/blog/how-node2vec-works): A blog post from which
  you can learn all about the node2vec algorithm. 
- [Understanding How Dynamic node2vec Works on Streaming
  Data](https://memgraph.com/blog/dynamic-node2vec-on-streaming-data): A blog
  post from which you can learn all about the dynamic node2vec algorithm. 
- [Link Prediction With node2vec in Physics Collaboration
  Network](https://memgraph.com/blog/link-prediction-with-node2vec-in-physics-collaboration-network):
  A demo on building a recommendation system using link predictions calculated
  with the node2vec algorithm.
- [Recommendation System Using Online Node2Vec With Memgraph
  MAGE](https://memgraph.com/blog/online-node2vec-recommendation-system): A demo
  on building an online recommendation system using k-means clustering and
  node2vec algorithm.

## Graph neural networks

Using the node2vec algorithm to determine node embeddings works well, but graph
neural networks (GNNs) are more precise. GNNs aim to get the node
representations automatically and efficiently by iteratively aggregating the
representations of node neighbors and combining them with their representation
from the previous iteration. GNNs can inductively learn about your dataset,
which means that after training is complete, you can apply their knowledge to a
similar use case, meaning you don't have to retrain the whole algorithm. 

![gnn](https://memgraph.com/docs/pages/ai-ecosystem/machine-learning/memgraph-gnn.png)

#### Algorithms
 

Here are the MAGE algorithms that are using GNNs:
- [Link prediction with
  GNN](https://memgraph.com/docs/advanced-algorithms/available-algorithms/gnn_link_prediction): Module
  for predicting links in the graph by using GNNs.
- [Node classification with
  GNN](https://memgraph.com/docs/advanced-algorithms/available-algorithms/gnn_node_classification):
  GNN-based node classification module.

#### Resources
 

In case you'd like to learn more about the topic and see
practical examples, check out the following resources:
- [Building a Recommendation System for Telecommunication Packages Using Graph
  Neural
  Networks](https://memgraph.com/blog/building-a-recommendation-system-for-telecommunication-packages-using-graph-neural-networks):
  A demo on how to build a recommendation system using Memgraph's link
  prediction with GNN.
- [Become an Inspector for a Day and Detect Fraudsters With Graph ML on
  Memgraph](https://memgraph.com/blog/become-an-inspector-for-a-day-and-detect-fraudsters-with-graph-ml-on-memgraph):
  A demo on how to build a fraud detection system using node classification with
  GNN.

## Temporal graph networks

Temporal graph networks (TGNs) are GNNs which work on temporal graph networks,
meaning they deal with continuous-time dynamic graphs.

![tgn](https://memgraph.com/docs/pages/ai-ecosystem/machine-learning/memgraph-tgn.png)

#### Algorithms
 

Here is the MAGE algorithm that uses TGNs:
- [Link prediction and node classification with
  TGN](https://memgraph.com/docs/advanced-algorithms/available-algorithms/tgn): A TGN-based module for
  link prediction and node classification.

#### Resources
 

In case you'd like to learn more about the topic, check out
the following resource:
- [Temporal Graph Neural Networks With Pytorch - How to Create a Simple
  Recommendation Engine on an Amazon
  Dataset](https://memgraph.com/blog/amazon-user-item-recommender-with-tgn-and-memgraph):
  An under-the-hood blog post explaining TGN in Memgraph and showcasing
  recommendation system demo using link prediction with TGN. 

## Want to learn more?

To learn more, check out [Enhancing AI with graph databases and LLMs
bootcamp](https://memgraph.com/academy/enhancing-ai-with-graph-databases-and-llms)
and [on-demand resources](https://memgraph.com/on-demand). Stay up to date with
[Memgraph events](https://memgraph.com/events) and watch videos from the [AI,
LLMs and GraphRAG YouTube
playlist](https://youtube.com/playlist?list=PL7Eotag2rRhYX6lZNbk7SPOcqREF7xzyU&si=RHDKio8o31KQ2QmV).
