Skip to content
BI & Data ScienceRecommender systems and collaborative filtering

Formulas for this chapter

Content-based prediction

P(u,i) = average of u's ratings on items sharing i's attribute

When the item has attributes and the user has some history. Works from the first rating, and on items nobody has rated yet.

u
The target user
i
The item whose rating is missing
attribute
In the assignment, the Type column: Sci-Fi or Action

Pearson similarity between users

sim(u,v) = CORREL(ratings of u, ratings of v) computed over the items both rated only

Step one of user-based collaborative filtering, once per other user. Anchor the target user's range with dollar signs so the formula fills down.

sim(u,v)
Correlation from -1 to +1; +1 identical taste, -1 opposite
shared items
Columns where both users have a numeric rating; CORREL selects them automatically

User-based collaborative filtering prediction

P(u,i) = rubar + [ sum over v in N of sim(u,v) x (r(v,i) - rvbar) ] / [ sum over v in N of |sim(u,v)| ] class layout: Ans = (Sum of Correl x Difference) / (Sum of |Correl|) + Average(u)

Filling one blank cell of the ratings matrix. Clip the answer to the rating range: the formula is unbounded.

rubar
The target user's own average rating, the baseline
N
Neighbourhood: only the users who themselves rated item i
r(v,i) - rvbar
Neighbour v's mean-centred rating of i, the Difference column
|sim(u,v)|
Absolute similarity, so positive and negative neighbours cannot cancel in the denominator

Item-based collaborative filtering prediction

P(u,i) = sum over j of sim(i,j) x r(u,j) / sum over j of |sim(i,j)|

The same arithmetic with the matrix transposed. Preferred at scale, because items are fewer than users and item-item similarities can be precomputed.

sim(i,j)
Similarity between items i and j, from how users rated them
r(u,j)
This user's own rating of the similar item j
Step 3 of 22
The real wordsTheory

Content-based filtering

Content-based filteringPredict from the item's own attributes and this user's history with similar items. No other user is consulted.

Section B's assignment supplies exactly one attribute, a Type column reading Sci-Fi or Action. That is deliberate: it is the hook the content-based half of the assignment hangs on.

predicted rating = average of this user's ratings on items of the same type

Simple, and it works from the first rating a user ever gives.