mysql - Return rows in common with another user in SQL (Collaborative Filtering) -
i'm trying build basic collaborative filtering recommendation system using mysql. have user rating table this:
user_id movie_id rating 1 131 342 3 <<< user 131 has rated movie 342 2 131 312 5 <<< , 312 3 122 312 4 4 213 342 5 5 141 342 5 <<< user 141 has rated 342 6 141 312 4 <<< , 312 (2 movies in common) 7 141 323 3 so i'm trying find similar users 131. want return users have @ least 2 movies in common , ratings above 3. should return rows 5 , 6 (as shown above).
this have far:
select * user_ratings rating >= 3 , movie_id in (select movie_id user_rating user_id = 131) , user_id != 131 this returns:
user_id movie_id rating 3 122 312 4 <<< don't want these 2 4 213 342 5 <<< 5 141 342 5 6 141 312 4 it returns movies users have in common 131, need show users have @ least 2 items in common. how this? i'm unsure of how proceed :(
you can first find user_ids have more or equal number of movies user_id = 131 rating > 3. use in in where clause additional data:
select * user_ratings user_id in( select user_id user_ratings movie_id in (select movie_id user_ratings user_id = 131) , rating > 3 group user_id having count(*) >= (select count(*) user_ratings user_id = 131) ) , rating > 3
Comments
Post a Comment