Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Link Prediction with Embeddings | Graph-Based Machine Learning Tasks
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Graph Theory for Machine Learning with Python

bookLink Prediction with Embeddings

Link prediction is a core task in graph-based machine learning where you try to predict which edges are missing or likely to form in a graph. This is useful in social networks for friend recommendations, in biological networks for discovering unknown interactions, and in knowledge graphs for inferring new relationships. The key idea is to use node embeddings—vector representations of nodes that capture structural and semantic information—to measure the likelihood of an edge existing between two nodes.

By representing each node as a vector, you can use a similarity function to score how likely it is that two nodes should be connected. If two node embeddings are very similar, it suggests that the nodes are related in the graph, even if there is not currently an edge connecting them. The higher the similarity score, the more likely it is that an edge should exist between the nodes. Common similarity functions include the dot product, cosine similarity, and L2 distance (negative Euclidean distance).

123456789101112131415161718192021
import numpy as np # Define a small undirected graph with 4 nodes (0, 1, 2, 3) edges = {(0, 1), (1, 2), (2, 3)} # existing edges # Generate random embeddings for each node (dimension=3) np.random.seed(42) embeddings = np.random.randn(4, 3) # Find all possible node pairs (excluding self-loops and existing edges) all_pairs = [(i, j) for i in range(4) for j in range(i+1, 4)] candidate_edges = [pair for pair in all_pairs if pair not in edges and (pair[1], pair[0]) not in edges] # Compute dot product similarity for each candidate edge def score(u, v): return np.dot(embeddings[u], embeddings[v]) print("Candidate edges and their similarity scores:") for u, v in candidate_edges: sim = score(u, v) print(f"Edge ({u}, {v}): similarity score = {sim:.3f}")
copy

1. What does a high similarity score between two node embeddings suggest in link prediction?

2. Which scoring function is commonly used for link prediction with embeddings?

question mark

What does a high similarity score between two node embeddings suggest in link prediction?

Select the correct answer

question mark

Which scoring function is commonly used for link prediction with embeddings?

Select the correct answer

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 3. Kapittel 1

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

bookLink Prediction with Embeddings

Sveip for å vise menyen

Link prediction is a core task in graph-based machine learning where you try to predict which edges are missing or likely to form in a graph. This is useful in social networks for friend recommendations, in biological networks for discovering unknown interactions, and in knowledge graphs for inferring new relationships. The key idea is to use node embeddings—vector representations of nodes that capture structural and semantic information—to measure the likelihood of an edge existing between two nodes.

By representing each node as a vector, you can use a similarity function to score how likely it is that two nodes should be connected. If two node embeddings are very similar, it suggests that the nodes are related in the graph, even if there is not currently an edge connecting them. The higher the similarity score, the more likely it is that an edge should exist between the nodes. Common similarity functions include the dot product, cosine similarity, and L2 distance (negative Euclidean distance).

123456789101112131415161718192021
import numpy as np # Define a small undirected graph with 4 nodes (0, 1, 2, 3) edges = {(0, 1), (1, 2), (2, 3)} # existing edges # Generate random embeddings for each node (dimension=3) np.random.seed(42) embeddings = np.random.randn(4, 3) # Find all possible node pairs (excluding self-loops and existing edges) all_pairs = [(i, j) for i in range(4) for j in range(i+1, 4)] candidate_edges = [pair for pair in all_pairs if pair not in edges and (pair[1], pair[0]) not in edges] # Compute dot product similarity for each candidate edge def score(u, v): return np.dot(embeddings[u], embeddings[v]) print("Candidate edges and their similarity scores:") for u, v in candidate_edges: sim = score(u, v) print(f"Edge ({u}, {v}): similarity score = {sim:.3f}")
copy

1. What does a high similarity score between two node embeddings suggest in link prediction?

2. Which scoring function is commonly used for link prediction with embeddings?

question mark

What does a high similarity score between two node embeddings suggest in link prediction?

Select the correct answer

question mark

Which scoring function is commonly used for link prediction with embeddings?

Select the correct answer

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 3. Kapittel 1
some-alt