# Item-item collaborative filtering

Item-item collaborative filtering, or item-based, or item-to-item, is a form of collaborative filtering for recommender systems based on the similarity between items calculated using people's ratings of those items. Item-item collaborative filtering was invented and used by Amazon.com in 1998. It was first published in an academic conference in 2001.
Earlier collaborative filtering systems based on rating similarity between users (known as user-user collaborative filtering) had several problems:
* systems performed poorly when they had many items but comparatively few ratings
* computing similarities between all pairs of users was expensive
* user profiles changed quickly and the entire system model had to be recomputed
Item-item models resolve these problems in systems that have more users than items. Item-item models use rating distributions per item, not per user. With more users than items, each item tends to have more ratings than each user, so an item's average rating usually doesn't change quickly. This leads to more stable rating distributions in the model, so the model doesn't have to be rebuilt as often. When users consume and then rate an item, that item's similar items are picked from the existing system model and added to the user's recommendations.

## Method

First, the system executes a model-building stage by finding the similarity between all pairs of items. This similarity function can take many forms, such as correlation between ratings or cosine of those rating vectors. As in user-user systems, similarity functions can use normalized ratings (correcting, for instance, for each user's average rating).
Second, the system executes a recommendation stage. It uses the most similar items to a user's already-rated items to generate a list of recommendations. Usually this calculation is a weighted sum or linear regression. This form of recommendation is analogous to "people who rate item X highly, like you, also tend to rate item Y highly, and you haven't rated item Y yet, so you should try it".

## Results

Item-item collaborative filtering had less error than user-user collaborative filtering. In addition, its less-dynamic model was computed less often and stored in a smaller matrix, so item-item system performance was better than user-user systems.

## Example

Consider the following matrix :
User - Article Matrix :
| User | Article 1 | Article 2 | Article 3 |
| John | Bought it | Bought it | Did not buy |
| Pierre | Bought it | Bought it | Bought it |
| Mary | Did not buy | Bought it | Did not buy |
If a user is interested in Article 1, which other item will be suggested to him by a system which is using Amazon's item-to-item algorithm ?
The goal is to propose the user the article with highest cosinus value. This is how we do it :
Firstly, we convert the User-Article matrix into a binary one and we create a simple matrix for each article.
User - Article Matrix (Binary) :
| User | Article 1 | Article 2 | Article 3 |
| John | 1 | 1 | 0 |
| Pierre | 1 | 1 | 1 |
| Mary | 0 | 1 | 0 |
* A1 = [1, 1, 0]
* A2 = [1, 1, 1]
* A3 = [0, 1, 0]
Secondly, we multiply matrix A1 by each matrix in order to find the dot product.
* A1 * A2 = (1*1) + (1*1) + (0*1) = 2
* A1 * A3 = (1*0) + (1*1) + (0*0) = 1
Thirdly, we find the norm of each vector.
* ||A1|| = ${\sqrt {1^{2}+1^{2}+0^{2}}}$ = ${\sqrt {2}}$ = 1.4142
* ||A2|| = ${\sqrt {1^{2}+1^{2}+1^{2}}}$ = ${\sqrt {3}}$ = 1.7320
* ||A3|| = ${\sqrt {0^{2}+1^{2}+0^{2}}}$ = ${\sqrt {1}}$ = 1
Fourthly, we calculate the cosine.
* A1 and A2 = COS(θ) =${\frac {A1*A2}{||A1||*||A2||}}$ = ${\frac {2}{{\sqrt {2}}*{\sqrt {3}}}}$= ${\frac {\sqrt {6}}{3}}$ = 0.8165
* A1 and A3 = COS(θ) =${\frac {A1*A3}{||A1||*||A3||}}$ = ${\frac {1}{{\sqrt {2}}*1}}$= ${\frac {1}{\sqrt {2}}}$ = ${\frac {\sqrt {2}}{2}}$ = 0.7071
Conclusion: If a user is interested in article 1. The algorithm item-to-item will suggest article 2.