Guest
Sign in to keep your graphs and progress.
Select an algorithm and generate steps to begin visualization
Two customers are alike when they buy the same things
Compares vertices by their neighbours, shared over all, and keeps the k most similar of each vertex: the basis of many recommendations
Select an algorithm and generate steps to begin visualization
Node similarity compares two vertices by the vertices they link to. The Jaccard score divides the neighbours they share by all the neighbours either of them has: 1 means exactly the same neighbours, 0 nothing in common. The overlap coefficient divides by the smaller neighbourhood instead, so a vertex whose few links all appear in a larger neighbourhood scores 1. On a directed graph the neighbours are the out-neighbours, the products a customer bought or the films a person watched, which makes the graph bipartite in spirit: people on one side, items on the other.
The visualizer takes each vertex that has links in turn, lists every other vertex that shares at least one neighbour with it and writes each score as a fraction, for instance Ben 2/3 = 0.67. Pairs with nothing in common are skipped, which is what keeps the method fast on large sparse graphs. Each vertex keeps its two most similar others, and these become new SIMILAR links, drawn dashed with their score. The panel lists every compared pair with Jaccard and overlap. In the example, five people and five items, Ann and Ben share two of three items, the most similar pair, so Game, which Ann has and Ben lacks, is the natural recommendation for Ben.
Node similarity is the core of collaborative filtering on a graph: customers who bought the same products, users who rated the same films, readers of the same papers. Neo4j Graph Data Science runs it as nodeSimilarity, with Jaccard, overlap or cosine, a topK and a cutoff, and writes the result back as SIMILAR relationships that later queries or community detection use. It also deduplicates records that point to the same addresses and phone numbers in fraud detection, groups genes by shared interactions and links documents that cite the same sources. For millions of vertices, approximate k-nearest-neighbour methods replace the exact comparison.
Compare only the pairs that share a neighbour, then keep each vertex's top k.
NodeSimilarity(G, k):
for each vertex a with outgoing links:
for each vertex b sharing a neighbour with a:
J(a, b) = |N(a) ∩ N(b)| / |N(a) ∪ N(b)|
O(a, b) = |N(a) ∩ N(b)| / min(|N(a)|, |N(b)|)
keep the k largest J(a, b) as SIMILAR links
return the SIMILAR linksThe pairs sharing a neighbour are found through the neighbours themselves: for each item, every pair of vertices linked to it. Pairs with nothing in common score 0 and are never touched, which is what makes the method practical on large sparse graphs.
Five people and the items they have, loaded on this page, with k = 2.
Example graph: Ann → Book, Film, Game. Ben → Book, Film. Cat → Film, Game, Tea. Dan → Tea, Mug. Eve → Game, Tea, Mug.
6 SIMILAR links: Ann – Ben and Dan – Eve at 0.67, Ann – Cat and Cat – Eve at 0.5, Ben – Cat and Dan – Cat at 0.25. Ben is most like Ann, so Game, which Ann has and Ben lacks, is the first recommendation for Ben.
Time: O(Σ deg(z)²) over the items z · Space: O(n + m + number of pairs)
Every pair that shares an item z is generated once per shared item, so the work is the sum over the items of their degree squared. Popular items dominate: an item held by 10,000 people creates 50 million pairs. Libraries therefore cap the degree, sample, or switch to an approximate k-nearest-neighbour search, which compares each vertex with a few candidates and improves the list in rounds.
Similarity scores and methods.
| Alternative | Prefer it when | Cost |
|---|---|---|
| Overlap coefficient | Being a subset should count as fully similar. Ben's two items are both among Ann's three, so overlap gives 1 where Jaccard gives 0.67. | same as Jaccard |
| Cosine similarity | The links carry weights, such as ratings or counts. With 0 or 1 weights it equals |N(a) ∩ N(b)| / √(|N(a)| · |N(b)|). | same as Jaccard |
| Approximate k-nearest neighbours on embeddings | Millions of vertices, or similarity beyond direct neighbours. Embed the vertices, for instance with node2vec or FastRP, then search for close vectors. | near-linear |
Read the full article: Bipartite Graphs Explained
Read the full article: Graph Neural Networks: A Practical Introduction
Related algorithms: Link Prediction, Hopcroft-Karp Matching, Bipartite Check, Clustering Coefficient, Louvain Community Detection
Built by Mohammed Islam Hadjoudj · Work with me