Similarity and Link Prediction Algorithms
Explore node similarity and link prediction algorithms that reveal hidden structure and likely future connections in a graph.
Similarity and Link Prediction Algorithms is a free Neo4j Graph Database Fundamentals lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Neo4j Graph Database Fundamentals learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Beyond Paths and Centrality
You have seen pathfinding, centrality, and community detection. Another family answers: how alike are two nodes and which connections are likely to form next?
What Is Node Similarity
Similarity algorithms score how comparable two nodes are based on the neighbors or items they share.
Two users who bought many of the same products are similar.
Jaccard Similarity
The Jaccard coefficient divides the size of the shared neighbor set by the size of the combined set. It ranges from 0 to 1.
// Jaccard = |A intersect B| / |A union B|
// 3 shared neighbors, 7 total distinct -> 0.43Running Node Similarity in GDS
The Graph Data Science library provides a node similarity procedure that compares nodes by shared relationships.
CALL gds.nodeSimilarity.stream('myGraph')
YIELD node1, node2, similarity
RETURN gds.util.asNode(node1).name AS a,
gds.util.asNode(node2).name AS b,
similarity
ORDER BY similarity DESC;Cosine and Overlap Similarity
Other measures include cosine similarity (for weighted vectors) and overlap similarity. Choose based on whether weights matter.
What Is Link Prediction
Link prediction estimates how likely two currently unconnected nodes are to connect in the future, based on graph structure.
It powers friend suggestions and product recommendations.
Common Neighbors
The simplest predictor: the more common neighbors two nodes share, the more likely they connect. Many social suggestions use this idea.
MATCH (a:Person {name: 'Alice'})-[:FRIEND]->(common)<-[:FRIEND]-(b:Person)
WHERE NOT (a)-[:FRIEND]->(b) AND a <> b
RETURN b.name, count(common) AS sharedFriends
ORDER BY sharedFriends DESC;Adamic-Adar
Adamic-Adar refines common neighbors by giving less weight to highly-connected shared neighbors, since a hub connection is less informative.
RETURN gds.alpha.linkprediction.adamicAdar(node1, node2) AS score;Preferential Attachment
Preferential attachment assumes nodes with many connections are more likely to gain more. It multiplies the degrees of the two nodes.
RETURN gds.alpha.linkprediction.preferentialAttachment(node1, node2) AS score;Choosing the Right Measure
No single measure is best. Test several against known outcomes and pick the one that predicts your real links most accurately.
Putting It to Use
Similarity and link prediction feed recommendation systems, deduplication, and network growth analysis. They turn structure into actionable suggestions.
Quick Check
Test your understanding of these algorithms.
Recap
You explored similarity and link prediction:
- Jaccard, cosine, and overlap measure node similarity
- Link prediction estimates future connections
- Common neighbors, Adamic-Adar, and preferential attachment are key predictors
- Test measures against real outcomes
Frequently asked questions
Is the “Similarity and Link Prediction Algorithms” lesson free?
Yes — the full text of “Similarity and Link Prediction Algorithms” is free to read here on the web, and the Neo4j Graph Database Fundamentals course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Neo4j Graph Database Fundamentals course, upgrade to CoddyKit PRO.
What will I learn in “Similarity and Link Prediction Algorithms”?
Explore node similarity and link prediction algorithms that reveal hidden structure and likely future connections in a graph. You practise Neo4j Graph Database Fundamentals with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Neo4j Graph Database Fundamentals?
No prior experience is required. Neo4j Graph Database Fundamentals on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Similarity and Link Prediction Algorithms” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Neo4j Graph Database Fundamentals lesson?
Yes. Every Neo4j Graph Database Fundamentals lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Pathfinding Algorithms (BFS, DFS)
- Centrality Algorithms (PageRank)
- Community Detection Algorithms
- Similarity and Link Prediction Algorithms