# Find similarity between two node clusters that are not connected

**URL:** <https://community.neo4j.com/t/find-similarity-between-two-node-clusters-that-are-not-connected/62008>\
**Category:** Graph Data Science / Graph Analytics\
**Created:** [April 12, 2023, 2:35pm UTC](https://community.neo4j.com/t/find-similarity-between-two-node-clusters-that-are-not-connected/62008 "2023-04-12T14:35:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![henry007](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/henry007/32/27619_2.png) [@henry007](https://community.neo4j.com/u/henry007)\
**Post date:** [April 12, 2023, 2:35pm UTC](https://community.neo4j.com/t/find-similarity-between-two-node-clusters-that-are-not-connected/62008/1 "2023-04-12T14:35:36Z")

</div>

Hello, I have data structured in a way as seen in the image below:

 ![image](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/1/4/14a65336dcc44bdd508fd027114cd9b7d1f20f41.png)

There are two people that have distinct interactions. Bob had a phone call, an order, received an email, and had a website visit. John's interactions were two orders, received an email, and had a website visit.

These two "Person" nodes are not connected by relationships, but I'd like to compute the similarity between them. After some research, there are graph similarity algorithms but those seem to mostly rely on relationships.

Is there a way to compute similarity between nodes based on Labels?

In this case, Bob & John would be roughly 75% similar as they share 3 node labels (Order, Email, WebsiteVisit).

Thank you!

---

<div class="post-metadata">

**Author:** ![alison.cossette](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/alison.cossette/32/27383_2.png) [@alison.cossette](https://community.neo4j.com/u/alison.cossette)\
**Post date:** [May 11, 2023, 7:26pm UTC](https://community.neo4j.com/t/find-similarity-between-two-node-clusters-that-are-not-connected/62008/2 "2023-05-11T19:26:39Z")

</div>

Hi Henry:

```auto
CALL gds.nodeSimilarity.stream('myGraph')
YIELD node1, node2, similarity
RETURN gds.util.asNode(node1).name AS Person1, gds.util.asNode(node2).name AS Person2, similarity
ORDER BY similarity DESCENDING, Person1, Person2

```

Details about the above can be seen here. [Node Similarity - Neo4j Graph Data Science](https://neo4j.com/docs/graph-data-science/current/algorithms/node-similarity/)

You will want to make sure that the graph projection you are using contains the nodes and relationships you note in your question above.

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [May 12, 2023, 12:05am UTC](https://community.neo4j.com/t/find-similarity-between-two-node-clusters-that-are-not-connected/62008/3 "2023-05-12T00:05:08Z")

</div>

I suppose you could compute the Jaccard Similarity measure between each pair of Person nodes using your definition of similar.

> **[Node Similarity - Neo4j Graph Data Science](https://neo4j.com/docs/graph-data-science/current/algorithms/node-similarity/)**
>
> This section describes the Node Similarity algorithm in the Neo4j Graph Data Science library. The algorithm is based on the Jaccard and Overlap similarity metrics.

Applying the definition to your use case, I believe you get the following:  
Jaccard Similarity Score = (Total number of connected nodes with labels in common)/(Total number of different labels among connected nodes for the two Person nodes)

---

<div class="post-metadata">

**Author:** ![michael.hunger](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/michael.hunger/32/27377_2.png) [@michael.hunger](https://community.neo4j.com/u/michael.hunger)\
**Post date:** [May 13, 2023, 9:05am UTC](https://community.neo4j.com/t/find-similarity-between-two-node-clusters-that-are-not-connected/62008/4 "2023-05-13T09:05:09Z")

</div>

If you just generally want to compare them for a "diff" you can also look apoc.diff.nodes

> **[Diff - APOC Documentation](https://neo4j.com/docs/apoc/5/comparing-graphs/node-difference/)**
>
> This section describes a function that displays the difference between two nodes.
