# User-User Collaborative Filtering

Consider the following ratings matrix. As the usual convention, each row represents a user and each column represents a movie.

<table><thead><tr><th width="150"></th><th width="150">Batman</th><th width="150">X-Men</th><th width="150">Star Wars</th><th width="150">Notebook</th><th>Titanic</th></tr></thead><tbody><tr><td><strong>Alice</strong></td><td>5</td><td>4.5</td><td>5</td><td>2</td><td>1</td></tr><tr><td><strong>Bob</strong></td><td>4.5</td><td>4</td><td></td><td>2</td><td>2</td></tr><tr><td><strong>Carol</strong></td><td>2</td><td>3</td><td>1</td><td>5</td><td>5</td></tr></tbody></table>

Intutively, we see that Bob's ratings are similar to Alice's, thus he is likely to also like Star Wars.

"Math-Speak", Alice's and Bob's ratings are highly correlated.

### Average Rating

Using average ratings has its limitations. It treats everyone's rating of the movie equally. For example, when using the average rating methodolgy, Bob's rating equally depends on Alice's and Carol's rating, even though he doesn't agree with Carol.

Following is the equation for average rating:

$$
s(i,j) = \frac{\sum\_{i^` \isin \Omega_j} r_{i^`j}}{|\Omega\_j|}
\\
where, \Omega\_j \equiv Set \hspace{0.1cm} of \hspace{0.1cm} all \hspace{0.1cm} users \hspace{0.1cm} who \hspace{0.1cm} have \hspace{0.1cm} rated \hspace{0.1cm} movie \hspace{0.1cm} j.
$$

### Weighted Rating

Weighted rating overcomes the limitation of average rating as it takes into account weightage of each rating. Following is the equation to calculate weighted rating of movie $$j$$​ by user $$i$$.

### Deviation

In recommender systems, rather than caring about absolute ratings, we care how much it deviates from a user's own average rating.

For example, if a user's average rating is 2.5, and the user rates a particular movie as a 5, it must be really good.

For a known rating $$j$$​ by user $$i$$​, deviation is given by the following equation:

$$
dev(i,j) = r(i,j) - ={r\_i}
\\
where, r(i,j) \equiv Known \hspace{0.1cm} rating \hspace{0.1cm} by \hspace{0.1cm} user \hspace{0.1cm} i \hspace{0.1cm} for \hspace{0.1cm} movie \hspace{0.1cm} j.
\\
\={r\_i} \equiv Average \hspace{0.1cm} rating \hspace{0.1cm} by \hspace{0.1cm} user \hspace{0.1cm} i \hspace{0.1cm} based \hspace{0.1cm} on \hspace{0.1cm} all \hspace{0.1cm} the \hspace{0.1cm} movies \hspace{0.1cm} s(he) \hspace{0.1cm} has \hspace{0.1cm} rated.
$$

​
