Last active
July 14, 2020 16:06
-
-
Save LeonardoMarrancone/ceffa166a0480ea85f6fe85519fd5015 to your computer and use it in GitHub Desktop.
cosine similarity with rating
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MATCH (p1:User {name: "Leonardo", surname:"Marrancone"})-[x:WATCH]->(m:Show)<-[y:WATCH]-(p2:User) | |
WITH COUNT(m) AS numbershows, SUM(x.rating * y.rating) AS xyDotProduct, | |
SQRT(REDUCE(xDot = 0.0, a IN COLLECT(x.rating) | xDot + a^2)) AS xLength, | |
SQRT(REDUCE(yDot = 0.0, b IN COLLECT(y.rating) | yDot + b^2)) AS yLength, | |
p1, p2 | |
RETURN p1.name as SelectedUser, p2.name as SimilarUser, xyDotProduct / (xLength * yLength) AS sim | |
ORDER BY sim DESC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment