Coding the Solution
Explore how to implement link prediction on a social network graph using the PyKEEN library. Learn to create synthetic graphs, train and evaluate knowledge graph embeddings, perform hyperparameter optimization, and generate friend recommendations based on model predictions.
The solution to the problem
Our aim is to generate friend recommendations for different people in the social network graph. We can formulate this as a link prediction or a knowledge graph completion task. Specifically, this is a task of head prediction or tail prediction.
Let's have a look at the following code and run it to generate the results:
Let’s look at the code explanation below:
Line 10: Creates a synthetic graph using the Watts-Strogatz model with
500nodes.Lines 13–20: Generate random unique names to relabel the nodes in the social network.
Lines 23–27: Relabel the nodes and remove self-loops.
Lines 30–41: Add edge attributes to the knowledge graph.
Lines 44–50: Create a ...