# Using cosine similarity to measure similarity between uses is not correct

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.

• When computing the similarity, only the item that rated by both users are under consideration. Mar 28, 2017 at 16:53
• 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. Feb 15 at 10:24

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$

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

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.

• If you are satisfied with the answer, please accept it. If not, you could consider leaving a comment detailing what you are missing. Mar 19 at 6:32