Link prediction
Link prediction estimates which pairs of nodes in a network are likely to form edges (now or in the future) using graph structure, similarity scores, path-based and learning methods.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Link prediction is used by engineers to recommend friends or connections, suggest items, detect missing or spurious links, and predict future interactions in social, collaboration, communication and knowledge networks. It converts network structure into rankings or binary predictions that feed recommender systems, anomaly detectors and evolution models.
Key ideas
- Adjacency matrix: for a graph with n nodes, the adjacency matrix A is an n×n matrix with A_{ij} = 1 if (i,j) ∈ E and 0 otherwise. For undirected graphs A is symmetric.
- Path: a sequence of nodes connected by edges. The length of a path is the number of edges.
- Similarity index / score: a numeric value s(i,j) assigned to node pair (i,j) used to rank pairs for link likelihood. Higher means more likely.
Common local similarity measures (useful in exams to define and derive):
- Common Neighbors (CN): s_CN(i,j) = |Γ(i) ∩ Γ(j)| where Γ(i) is the neighbour set of i. Assumption: nodes sharing more neighbours are more likely to connect (triadic closure).
- Jaccard coefficient (JC): s_J(i,j) = |Γ(i) ∩ Γ(j)| / |Γ(i) ∪ Γ(j)|. Assumption: similarity normalized by neighbourhood size.
- Adamic–Adar (AA): s_AA(i,j) = sum_{z ∈ Γ(i) ∩ Γ(j)} 1 / ln(deg(z)) (natural logarithm). Assumption: common neighbours with low degree are stronger evidence.
- Preferential Attachment (PA): s_PA(i,j) = deg(i)·deg(j). Assumption: high-degree nodes attract more links (rich-get-richer).
Path-based and global measures:
- Katz index: s_Katz(i,j) = sum_{l=1}^{∞} β^l · (A^l){ij}. Here (A^l){ij} counts number of paths length l between i and j; β is a damping factor chosen such that 0 < β < 1/λ_max(A) for convergence (see condition below). Assumption: all paths contribute, with longer paths exponentially downweighted.
- Convergence condition: the series converges if β < 1 / λ_max(A) where λ_max(A) is the largest eigenvalue (spectral radius) of A. Under that condition the closed form is s_Katz = ((I − βA)^{-1} − I)_{ij}.
- Resource Allocation (RA): s_RA(i,j) = sum_{z ∈ Γ(i) ∩ Γ(j)} 1/deg(z). This is a local, common-neighbours-based measure (not global); similar to AA but uses 1/deg instead of 1/ln(deg).
Learning-based methods:
- Supervised link prediction: treat each candidate pair (i,j) as an instance with features (CN, JC, AA, PA, path-based scores, node attributes, embeddings) and label 1 if edge exists in future/training positive set, 0 otherwise. Train classifier (logistic regression, random forest) using cross-validation. Prefer temporal or future-snapshot splits over random cross-validation to respect time ordering and avoid leakage.
- Embedding / representation learning: compute node vectors (node2vec, DeepWalk, matrix factorization). Then score pair (i,j) by similarity of vectors (dot product, cosine) and rank.
Evaluation metrics:
- AUC (Area Under ROC curve): probability a random positive pair is ranked above a random negative pair. For binary / ranking evaluation.
- Precision@k: fraction of true links among top-k predicted pairs. Important when only top recommendations matter.
Diagrams to draw for exam answers:
- For CN and JC: draw 4 nodes A,B,C,D with edges A–C, B–C, A–B (triangle) and a separate node D connected only to C. Label neighbourhoods Γ(A), Γ(B) and show intersection and union sets. For Katz: draw two nodes i and j and show two distinct length-2 and length-3 paths between them, label path lengths and weights β^2 and β^3.
Assumptions to state in answers: graph type (directed/undirected), whether we treat edges as undirected for indices, whether time ordering (predicting future vs imputing missing links), and whether node attributes are available.
Formulas
s_CN(i,j) = |Γ(i) ∩ Γ(j)| — Γ(i): neighbour set of i; unitless; applies for undirected graphs.
s_J(i,j) = |Γ(i) ∩ Γ(j)| / |Γ(i) ∪ Γ(j)| — unitless; applies when normalising by neighbourhood size.
s_AA(i,j) = sum_{z ∈ Γ(i) ∩ Γ(j)} 1 / ln(deg(z)) — deg(z) is degree of z; ln is natural logarithm; unitless; applies when deg(z) > 1.
s_RA(i,j) = sum_{z ∈ Γ(i) ∩ Γ(j)} 1 / deg(z) — unitless; local measure; penalizes high-degree common neighbours more strongly than AA.
s_PA(i,j) = deg(i) · deg(j) — degree is integer; unitless; applies under preferential-attachment assumption.
s_Katz(i,j) = sum_{l=1}^{∞} β^l · (A^l)_{ij} — β is damping factor (unitless). Converges if β < 1/λ_max(A). Closed form: s_Katz = ((I − βA)^{-1} − I)_{ij}.
AUC = P(score(positive) > score(negative)) — probability interpretation; unitless; used to compare ranking quality.
Precision@k = (# true positives in top-k) / k — unitless; used when recommending top-k links.
Worked examples
Example 1 — numerical, small graph (step-by-step):
- Graph nodes: A,B,C,D,E. Edges (undirected): A–B, A–C, B–C, C–D, D–E.
- Adjacency matrix A (order A=1,B=2,C=3,D=4,E=5): Row1: [0,1,1,0,0] Row2: [1,0,1,0,0] Row3: [1,1,0,1,0] Row4: [0,0,1,0,1] Row5: [0,0,0,1,0]
Compute scores for candidate pairs (A,D), (B,D), (A,E). Step 1: Common Neighbors
- Γ(A) = {B,C}, Γ(B) = {A,C}, Γ(D) = {C,E}, Γ(E) = {D}.
- CN(A,D)=|{B,C} ∩ {C,E}| = 1.
- CN(B,D)=|{A,C} ∩ {C,E}| = 1.
- CN(A,E)=|{B,C} ∩ {D}| = 0.
Step 2: Jaccard
- J(A,D)=1 / |{B,C,E}| = 1/3 ≈ 0.333.
- J(B,D)=1 / |{A,C,E}| = 1/3 ≈ 0.333.
- J(A,E)=0 / |{B,C,D}| = 0.
Step 3: Adamic–Adar
- The common neighbour for (A,D) and (B,D) is C with deg(C)=3.
- s_AA = 1 / ln(3). ln(3) ≈ 1.098612, so 1/ln(3) ≈ 0.910239.
- s_AA(A,D) ≈ 0.910239; s_AA(B,D) ≈ 0.910239; s_AA(A,E)=0.
Step 4: Preferential Attachment
- deg(A)=2, deg(B)=2, deg(D)=2, deg(E)=1.
- s_PA(A,D)=2·2=4; s_PA(B,D)=4; s_PA(A,E)=2·1=2.
Step 5: Katz (approximate with β=0.1 using terms l=1..3)
- Compute A^2 (paths of length 2): A^2 = [2,1,1,1,0; 1,2,1,1,0; 1,1,3,0,1; 1,1,0,2,0; 0,0,1,0,1]
- (A^1){1,4}=0, (A^2){1,4}=1. Compute A^3_{1,4}=1 (by multiplication or counting). Similarly for (2,4) A^2=1, A^3=1. For (1,5) A^2=0, A^3=1.
- Katz approx: s ≈ β·A^1 + β^2·A^2 + β^3·A^3.
- s_Katz(A,D) ≈ 0 + 0.01·1 + 0.001·1 = 0.011.
- s_Katz(B,D) ≈ 0.011.
- s_Katz(A,E) ≈ 0 + 0 + 0.001·1 = 0.001.
Final ranked order (tie-breaking by next criteria): A–D ≈ B–D > A–E. Numeric answers: CN: A–D=1, B–D=1, A–E=0; Jaccard ≈ 0.333,0.333,0; AA ≈ 0.910,0.910,0; PA: 4,4,2; Katz ≈ 0.011,0.011,0.001.
Example 2 — model exam answer (short essay question): Question: Explain the difference between local and global link prediction methods, give two examples of each, state their assumptions and computational costs. Model answer (points to include):
- Define local methods (use only node neighbourhoods); examples: Common Neighbours, Adamic–Adar. State assumption: triadic closure—links form among nodes that share neighbours. Complexity: computing CN for all pairs can be O(n·d^2) or using adjacency lists O(sum_v deg(v)^2) which is cheap on sparse graphs.
- Define global/path-based methods (use entire graph structure, paths of any length); examples: Katz, matrix-factorization. State assumption: influence travels along paths; longer paths less informative (Katz uses damping). Complexity: Katz with closed form needs matrix inversion O(n^3) or solving linear system; not feasible for very large graphs without approximation (truncated sums, spectral methods).
- Conclude: choose local for very large sparse networks when speed matters; choose global when longer-range connectivity matters and you can afford more compute or approximations.
(End of model answer should state trade-offs and refer to supervised/embedding approaches briefly.)
Common mistakes
- Using ln(deg(z)) in Adamic–Adar but accidentally using log base 10 — specify natural log in answers.
- Forgetting the convergence condition β < 1/λ_max for Katz and claiming closed-form inverse without it.
- Evaluating on all non-edges as negatives without sampling; leads to class imbalance and skewed metrics — report AUC or precision@k appropriately.
- Treating degree product (PA) as a probability instead of a score; it is unbounded and must be normalized if you need probabilities.
For your exam
Kinds of questions to expect:
- Definitions: define link prediction, adjacency matrix, CN, Jaccard, Adamic–Adar, Katz, AUC.
- Short notes: compare local vs global methods, describe supervised link prediction pipeline, discuss evaluation metrics.
- Derivations: derive Katz closed-form from infinite series and show convergence condition β < 1/λ_max(A) (show steps: matrix geometric series sum_{l=0}∞ (βA)^l = (I − βA)^{-1}).
- Numericals: given a small graph, compute CN, Jaccard, AA, PA and Katz approximation for candidate pairs — show steps and final numeric values.
- Diagrams: draw small graphs and label neighbourhoods, show counted paths of length 2 and 3 for Katz.
What a full-marks answer includes:
- Clear definitions with bold terms, graph type assumptions, step-by-step derivation or computation with formulas shown, any numeric values checked and units or unitless specified, and a short discussion of assumptions and complexity.
Quick check
- Define Common Neighbors in one line.
- Write the Katz index formula and the simple convergence condition.
- For nodes i and j with Γ(i)∩Γ(j) = {z} and deg(z)=10, what is the Adamic–Adar contribution from z (numeric to 3 decimals)?
Answers: 1) s_CN(i,j)=|Γ(i) ∩ Γ(j)|. 2) s_Katz(i,j)=sum_{l=1}∞ β^l (A^l)_{ij}, converges if β < 1/λ_max(A). 3) 1 / ln(10) ≈ 0.434.
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?