I have a "User x Item" matrix as below:

user item1 item2 item3
u1   2     0     3
u2   1     2     0
u3   4     3     1
u4   0     2     2

I want to computer the similarity between items based on users. For example, to calculate similarity between items i1 and i2, I only choose users who have assigned values to both of these items.

The cosine similarity between two items (i1 and i2) is as follows:

cos(v1,v2) = (1*2 + 4*3)/sqrt[(1 + 4)*(16+9)] 

My question is for item-to-item similarity, should I consider all users, or just common users who assigned values to the items?


1 Answer 1


Filtering users will create bias in your training data. This may be good or bad, depending on your data and goals. The best way to find out, for your specific system, is to try and test both methods, optimizing for whatever metric you choose is best.

Honestly, I think you should consider all users. Say you have a system for recommending movies. In this system, i1 represents a children's movie, that is rated by users u1 through u5, with u5 being a parent and u1, u2, u3 and u4 children. Similarly, i2 represents a terror movie, that is rated by users u5 through u9, all adults. In such a system, u5 being the only common ground between i1 and i2, if this user rated both positively and you only consider them, then you will have a high similarity between the items; but if you consider all users that rated either movie, you will have a very low similarity.

Or in other words, I think intuitively it's best to consider a missing rating as a false/negative rating. Excluding terms where both ratings are zero makes no difference in the cosine similarity anyway. But again, you should run and test it.

  • $\begingroup$ yes, i agree the method wont work well if there was only one common user between items..i may tackle this by assigning a minimum number of users for both items..Excluding terms where both ratings are zero makes no difference in the cosine similarity anyway (+1) $\endgroup$ Sep 13, 2017 at 7:23

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.