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.
How link prediction scores node pairs
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.
Families of link prediction methods
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.
| Family | Score based on | Examples | Typical use |
|---|---|---|---|
| Heuristic similarity | Shared neighbors and paths | Common neighbors, Adamic-Adar, Katz index | Strong, cheap baselines |
| Shallow embeddings | Learned vector per node | DeepWalk, node2vec, matrix factorization | Static, transductive graphs |
| Graph neural networks | Message passing over features | GCN or GraphSAGE encoder with decoder | Graphs with rich node attributes |
| Subgraph and pair models | Local structure around the pair | SEAL, NBFNet, labeling tricks | Highest accuracy on structural tasks |
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.
| Heuristic | Definition in words | Strength |
|---|---|---|
| Common neighbors | Number of shared neighbors | Simple, fast, interpretable |
| Jaccard coefficient | Shared neighbors divided by all neighbors | Normalizes for node degree |
| Adamic-Adar | Shared neighbors weighted by inverse log degree | Rewards rare shared contacts |
| Preferential attachment | Product of the two degrees | Captures hub growth |
| Katz index | Weighted count of all paths, shorter paths count more | Uses global structure |
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.
Link prediction in knowledge graphs
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.
Evaluating link prediction correctly
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.
| Metric | What it measures | Caution |
|---|---|---|
| AUC-ROC | Probability a true edge outranks a random non-edge | Inflated by easy random negatives |
| Average precision | Precision across recall levels | Sensitive to negative sampling ratio |
| Hits@K | Share of true edges ranked in the top K | Depends on candidate set size |
| Mean reciprocal rank | Average inverse rank of the true edge | Standard in knowledge graph completion |
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.