I have a theoretical question. I have implemented a recommender system using collaborative filtering method. There, I am using cosine similarity method to calculate similarity between two users. I have user-item ratings matrix and I get two raws(user feature vectors) and calculate cosine similarity. As an example consider following example vectors.

a = [0 0 0 1 0]
b = [0 0 0 0 0]

If I use cosine similarity, I am getting large value for these users as most of the items haven't been rated by both users. So my question is, is it correct to consider having unrated items as similarity between users? IMO, there is no point of using unrated item's ratings to calculate similarity as it is misleading.

What is your idea about this issue? Is any remedy for this issue ?

  • 1
    $\begingroup$ When computing the similarity, only the item that rated by both users are under consideration. $\endgroup$
    – statmlben
    Commented Mar 28, 2017 at 16:53
  • $\begingroup$ Could there not be information in what items users choose to rate or not rate? However, I'd be careful how I encode "not-rated" as you probably don't want that to be considered as the worst possible rating. $\endgroup$
    – Björn
    Commented Feb 15, 2022 at 10:24

2 Answers 2


Cosine similarity for the two users a and b gives zero, because one vector is zero and a zero vector has cosine similarity zero to any vector.

So, if you get a large value for those two users, you are not using cosine similarity.

  • $\begingroup$ If you are satisfied with the answer, please accept it. If not, you could consider leaving a comment detailing what you are missing. $\endgroup$
    – frank
    Commented Mar 19, 2022 at 6:32

You only need to consider the set of items that have been rated by both the users, and compute the similarity using those.

Let that set be $I_{a,b}$. Then,

$sim_{a,b} = \sum_{i \in I_{a,b}} a_i b_i$

  • $\begingroup$ Presumably you mean the Union of the two users’ sets and not the intersection $\endgroup$
    – Sycorax
    Commented Jun 15, 2021 at 12:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.