Link prediction

Also known as: edge prediction

On this page 7

Link prediction is the task of estimating the likelihood that an edge exists between two nodes of a graph when that edge is missing, hidden or has not yet formed. In graph learning, it is one of the three core tasks alongside node classification and graph classification, and it is also called edge prediction.

A link prediction model assigns a score to each candidate node pair and ranks pairs by that score. The same formulation covers friend recommendations in social networks, drug-target interactions in biology, product recommendations in bipartite user-item graphs and completion of knowledge graphs, where the edges carry relation types.

Every link prediction method follows the same pattern: it computes a pair score s(u, v) for nodes u and v, then treats high scores as predicted links. Methods differ in where that score comes from, ranging from hand-crafted neighborhood statistics to learned node embeddings and graph neural networks.

Learned approaches usually split the work into an encoder and a decoder. The encoder maps each node to a vector, for example with node2vec, a graph convolutional network or GraphSAGE. The decoder combines two vectors into a score, most often with a dot product, a bilinear form or a small multilayer perceptron, followed by a sigmoid to produce a probability.

Training relies on negative sampling. Observed edges serve as positive examples, while randomly drawn non-edges serve as negatives, and the model minimizes a binary cross-entropy or ranking loss. The choice of negatives strongly affects results, because random pairs are usually trivially easy to reject.

Link prediction methods fall into four broad families, each with a distinct assumption about why links form. The table compares them by mechanism and typical use.

FamilyScore based onExamplesTypical use
Heuristic similarityShared neighbors and pathsCommon neighbors, Adamic-Adar, Katz indexStrong, cheap baselines
Shallow embeddingsLearned vector per nodeDeepWalk, node2vec, matrix factorizationStatic, transductive graphs
Graph neural networksMessage passing over featuresGCN or GraphSAGE encoder with decoderGraphs with rich node attributes
Subgraph and pair modelsLocal structure around the pairSEAL, NBFNet, labeling tricksHighest accuracy on structural tasks
Main families of link prediction methods

Classical heuristics remain surprisingly competitive. They encode the principle of triadic closure, the tendency of two nodes with a common neighbor to connect, which holds strongly in homophilous networks such as social graphs. The next table shows how the most common heuristics are defined.

HeuristicDefinition in wordsStrength
Common neighborsNumber of shared neighborsSimple, fast, interpretable
Jaccard coefficientShared neighbors divided by all neighborsNormalizes for node degree
Adamic-AdarShared neighbors weighted by inverse log degreeRewards rare shared contacts
Preferential attachmentProduct of the two degreesCaptures hub growth
Katz indexWeighted count of all paths, shorter paths count moreUses global structure
Common heuristic scores for a node pair

A known weakness of plain GNN encoders is that they produce node-level embeddings independently, so they cannot always tell two structurally symmetric nodes apart. Subgraph methods solve this with labeling tricks that mark the target pair, which explains their stronger results on many benchmarks.

In a knowledge graph, edges are typed triples of the form head, relation and tail, so link prediction becomes knowledge graph completion: given a head and a relation, rank all possible tails. Models such as TransE, DistMult and RotatE learn embeddings for both entities and relations.

Each model uses a different scoring geometry. TransE treats a relation as a translation vector, DistMult as an element-wise scaling, and RotatE as a rotation in complex space, which lets it represent symmetric, inverse and compositional relations. Relational graph convolutional networks can serve as encoders for the same task.

Evaluation hides a portion of known edges and measures how well the model recovers them. Because real graphs are sparse, the number of non-edges vastly exceeds the number of edges, so ranking metrics are generally more informative than accuracy.

MetricWhat it measuresCaution
AUC-ROCProbability a true edge outranks a random non-edgeInflated by easy random negatives
Average precisionPrecision across recall levelsSensitive to negative sampling ratio
Hits@KShare of true edges ranked in the top KDepends on candidate set size
Mean reciprocal rankAverage inverse rank of the true edgeStandard in knowledge graph completion
Standard metrics for link prediction

Data leakage is the most frequent evaluation error. Test edges must be removed from the message-passing graph during training, otherwise the encoder sees the answers. For temporal graphs, splits must follow time, training on earlier edges and testing on later ones, which mirrors real future-link forecasting. Knowledge graph benchmarks also use a filtered setting that excludes other known true triples from the ranking.

Practical limitations and design choices

Scoring every node pair grows quadratically with graph size, so production systems first generate a short list of candidates, often with approximate nearest neighbor search over embeddings, and then rerank them with a stronger model.

  • Cold-start nodes with no edges depend entirely on their features, so shallow embeddings fail for them.
  • Heterophilous graphs, where unlike nodes connect, weaken the assumptions behind triadic closure heuristics.
  • Hard negative sampling improves realism but risks treating unobserved true links as negatives.
  • Feedback loops arise when recommended links are accepted and then reused as training data.

A sound workflow therefore starts with heuristic baselines such as Adamic-Adar, adds a GNN or subgraph model only when it clearly beats them under a leakage-free split, and monitors predictions after deployment for drift and bias.

Understanding it simply

Link prediction guesses which connections are missing in a network. Think of a map of who knows whom. If two people share many friends, they probably know each other too, or soon will.

A computer looks at the existing connections. It then gives every possible pair a score. The highest scores become suggestions, such as people you may know or products you may like. The guesses are not certain. They are a ranked list of likely links.

Applied in practice

A pharmaceutical research group builds a graph of about 20,000 proteins and 8,000 compounds, with edges for known drug-target interactions and protein-protein interactions. Their goal is to find untested compound-protein pairs worth checking in the laboratory, where each assay is costly.

They hold out 10% of known interactions, removed from the training graph, and compare an Adamic-Adar baseline with a GraphSAGE encoder that uses chemical and sequence features. The GNN reaches a clearly higher Hits@50 on the held-out edges, mainly because it can score compounds with few known links. The team sends the top 100 predicted pairs to the laboratory, where a meaningful share is confirmed, and they add the confirmed and rejected results back as labeled training data.