Skip to content

Instantly share code, notes, and snippets.

@LeonardoMarrancone
Created July 14, 2020 15:48
Show Gist options
  • Save LeonardoMarrancone/3ad97000a2e7a32c67cb152064f2d856 to your computer and use it in GitHub Desktop.
Save LeonardoMarrancone/3ad97000a2e7a32c67cb152064f2d856 to your computer and use it in GitHub Desktop.
Cosine similiraty with GDSL
MATCH (p1:User {name: 'Leonardo', surname:"Marrancone"})-[x:WATCH]->(movie)<-[y:WATCH]-(p2:User)
WHERE p2 <> p1
WITH p1, p2, collect(x.rating) AS p1Ratings, collect(y.rating) AS p2Ratings
RETURN p1.name AS SelectedUser,
 p2.name AS SimilarUser,
 gds.alpha.similarity.cosine(p1Ratings, p2Ratings) AS sim
ORDER BY sim DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment