Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
07-26-2022 08:27 AM
Hi,
I've been trying to code the above r from the MOVIE Lens database and i dont really get how to do it. Can someone help? I just registered with the community and i dont really understand how this works, i would appreciate any help.
I tried the following code
MATCH (p1:Movie)-[x:RATED]->(Movie{title: 'Titanic'})<-[x2:RATED]-(p2:Movie)
WHERE p2 <> p1
WITH p1, p2, collect(x.rating) AS p1Ratings, collect(x2.rating) AS p2Ratings
WHERE size(p1Ratings) > 10
RETURN p1.name AS from,
p2.name AS to,
gds.similarity.cosine(p1Ratings, p2Ratings) AS similarity
ORDER BY similarity DESC
Solved! Go to Solution.
07-26-2022 09:42 AM - edited 07-26-2022 09:44 AM
Hello @miklov 😊
This query should help you, I did on the Movie database (there is no result for this movie):
MATCH (m:Movie {title: 'The Da Vinci Code'})
WITH m, [(m)<-[r:REVIEWED]-(:Person) | r.rating] AS ratings_m
CALL {
WITH m, ratings_m
MATCH (n:Movie)
WHERE m <> n
WITH ratings_m, n, [(n)<-[r:REVIEWED]-(:Person) | r.rating] AS ratings_n
WHERE size(ratings_n) > 0 AND size(ratings_m) = size(ratings_n)
RETURN n, gds.similarity.cosine(ratings_m, ratings_n) AS similarity
}
RETURN m.title AS m1, n.title AS m2, similarity
Be careful, the lists of values in the similarity function must have the same size.
Regards,
Cobra
07-26-2022 09:42 AM - edited 07-26-2022 09:44 AM
Hello @miklov 😊
This query should help you, I did on the Movie database (there is no result for this movie):
MATCH (m:Movie {title: 'The Da Vinci Code'})
WITH m, [(m)<-[r:REVIEWED]-(:Person) | r.rating] AS ratings_m
CALL {
WITH m, ratings_m
MATCH (n:Movie)
WHERE m <> n
WITH ratings_m, n, [(n)<-[r:REVIEWED]-(:Person) | r.rating] AS ratings_n
WHERE size(ratings_n) > 0 AND size(ratings_m) = size(ratings_n)
RETURN n, gds.similarity.cosine(ratings_m, ratings_n) AS similarity
}
RETURN m.title AS m1, n.title AS m2, similarity
Be careful, the lists of values in the similarity function must have the same size.
Regards,
Cobra
07-27-2022 01:06 AM
Hello Cobra,
Thank you very very much for the quick reply, appreciated. So the outcome should be (no changes, no records)? Also i have a few more questions on this database, would you be able to help?
Thank you very much,
Mikaella
07-27-2022 01:25 AM
The movie The Da Vinci Code has no similar movies so there is no result but this query can be transposed to other databases. The Movie database is not the best one to test GDS algorithms.
Feel free to ask your questions.
Regards,
Cobra
07-27-2022 05:47 AM
Thank you very much. I have send you a private message 🙂
07-27-2022 10:30 AM
Hi miklov,
I know you've already gotten some help here, but there is a semantic error in your query that you may have overlooked:
MATCH (p1:Movie)-[x:RATED]->(Movie{title: 'Titanic'})<-[x2:RATED]-(p2:Movie)
p2 should be a User and not a Movie, I believe.
All the sessions of the conference are now available online