# Cosine similarity for recommendation systems

Recently picked up recommendation systems and was going through User Based Collaborative Filtering(UB-CF).

Somewhere in the text, it specified that cosine similarity is one of the measures to find similar users and then give a recommendation.

for example a movie recommendation model:

To begin we make a matrix of users and movies filled with the ratings they have provided. now consider

       movie1 movie2 movie3
User1   5       5      5
User2   1       1      1


In this case, the cosine similarity will be 1 while both the users have given a very different opinion of the movie and are not similar. How such issues are handled by cosine similarity? Is it not misleading?

PS: I understand that the case is way too hypothetical from a recommendation system point of view where I considered only 3 movies and both the users have watched it while in reality the matrix would be way sparse.

When using cosine similarity, you makes the assumption that User2 is a very difficult person who tend to give very low rating whereas User1 likes every movie. So 1 may be a very good rating for User2. Of course in this extreme case you can consider it is an issue that cosine similarity does not handle.

If you consider this example instead:

       movie1 movie2 movie3 movie4
User3   4       4      4      5
User4   2       2      2      3
User5   2       2      3      2


User3 and User4 are considered similar by cosine similarity because they prefer movie4 to all other movies regardless the mean of their ratings. User5 is considered different since it prefers movie3.

• Thanks for the explanation. Since you brought up "difficult person", if we say my 4 is a difficult person's 2.5, would normalizing the rating for each user help? @stanislas Commented Nov 16, 2019 at 23:35
• and what if the person is not that picky and these were the true ratings. User3 and user4 happened to be close on 1 movie but 3 other movies they had a different opinion Commented Nov 16, 2019 at 23:45
• The cosine being the dot product divided by the norms of the two vectors, it is already normalizing the rating for each user. Commented Nov 16, 2019 at 23:46
• If the interpretation in your comment of the rating happens to be the reality, then in this case cosine similarity would be misleading. When using a similarity measure (in this case the cosine) we are making assumptions. Commented Nov 16, 2019 at 23:53