CTU logo
NIE-PML · CTU FIT

Memory-based Approaches

Personalised Machine Learning

Where We Are

Previously: lecture 2
We learned latent representations, $X \approx UV^\top$, fitted by ALS.
model-based: fit latent factors, then score
Today
Reuse neighbouring users or items to score candidates.
No latent-factor optimisation in basic k-NN; neighbourhood construction can still happen offline.
Question
Whose behaviour provides useful evidence?

Our Running Example

Completion fractions
$0.8$ = 80% of the movie watched, not an 80% chance of liking it. $0$ = no recorded watch.
completion matrix $X$
profile coordinatescandidate evidence
userM1M2M3
Anna0.40.20
Pavel0.80.41
Jan00.80.7
Mario0.40.40
Luigi0.20.30
Anna, M3: not yet observed; a candidate, not a dislike
00.50.511M1 completionM2 completionAnnaPavelJanMarioLuigi
Question
Who can provide evidence about Movie 3 for Anna?

A k-NN Warm-up

1.62.02.43.13.43.63.74.1?
0 · Look at the data
Labelled points and one grey point to classify.
1 · Compute distances
From the grey point to every labelled point.
2 · Keep the $k$ nearest
rankclassdistance
11.6
22.0
32.4
43.1
3 · Vote, with $k = 3$
yellow: 2 · green: 1
the grey point is predicted yellow

From Votes to Evidence

Recorded behaviour is not a class label: instead of voting, we average the evidence.

Classification
The $k$ neighbours vote and the majority class wins.
green, green, yellow → green
Recommendation
The $k$ neighbours report whether they interacted with the candidate; we average.
neighbourwatched M3?adds
neighbour 111
neighbour 200
evidence for M3: $\;\tfrac{1}{2}(1 + 0) = 0.5$
An observed interaction adds evidence. No recorded interaction adds no positive evidence.

The Recipe of a k-NN Recommender

Every k-NN recommender is defined by three choices.

1 · Representation
Which vector describes a user or an item?
2 · Similarity
How close are two vectors?
3 · Aggregation
How many neighbours, and how do we combine them?

What coordinates describe a user or an item?

Collaborative vs Content-based Filtering

Two sources of similarity: what people do and what items are.

Collaborative filtering
Day oneAnnaBobSPORTSboth read sports newsDay twoAnnaPOLITICSAnna reads politicsBob, so Bob gets it
similar behaviour: Bob gets politics
Content-based filtering
Day oneBobSPORTSfootballBob reads sports newsDay twoBobSPORTStennisSPORTScyclingSPORTSfootballother sports articles are recommended
similar item attributes: Bob gets more sports

Four Ways to Find Neighbours

Interactionsneighbours from recorded behaviour
Attributesneighbours from descriptions
Users
User interaction profiles
compare rows
users with similar recorded behaviour
User attributes
$\mathbf{a}_i$: nationality, age
attribute-based user neighbours (demographic matching)
Items
Item interaction profiles
compare columns
items with similar audiences
Item attributes
$\mathbf{b}_j$: action, drama
content-based item neighbours

Content-based: Describing Items

What is the best way to represent these items for finding neighbours?

Office chair
1 105 CZK
Egg chair
24 937 CZK
Egg chair
24 945 CZK
Football shirt
1 299 CZK
as attribute vectors $\mathbf{b}_j$
itemblackredchairT-shirtprice (CZK)
Office chair10101 105
Egg chair101024 937
Egg chair011024 945
Football shirt01011 299

Same Items, Different Neighbours

as attribute vectors $\mathbf{b}_j$
itemblackredchairT-shirtprice (CZK)price scaled
Office chair10101 1050.00
Egg chair101024 9371.00
Egg chair011024 9451.00
Football shirt01011 2990.01

Euclidean distance from the office chair:

Price in CZK
Football shirt194
Egg chair (black)23 832
Egg chair (red)23 840
a T-shirt is closer than any chair
Price scaled to $[0, 1]$
Egg chair (black)1.00
Egg chair (red)1.73
Football shirt2.00
the other black chair
Feature representation and scale change the neighbourhood.

Neighbours from Attributes

Attribute-based user neighbours: describe each user by $\mathbf{a}_i = (\text{nationality}, \text{age})$.

NationalityAge (scaled)0100.51AnnaPavelJanMarioLuigi
user attributes
usernationalityage (scaled)
Anna10.31
Pavel10.27
Jan10.18
Mario00.89
Luigi00.91
nationality: two categories, coded 0 and 1
distances from Anna
userdistancewatched M3
Pavel0.041
Jan0.131
Mario1.16 
Luigi1.17 
Evidence, $k = 2$
$$\text{M3 evidence} = \tfrac{1}{2}(1 + 1) = 1$$
These attributes select Pavel and Jan.

Neighbours from Interactions

Describe the same users by what they watched, columns 1 and 2 of $X$: $\mathbf{h}_i = (X_{i1}, X_{i2})$.

00.50.511M1 completionM2 completion0.4470.721AnnaPavelJanMarioLuigi
completion profiles $\mathbf{h}_i$
userM1M2
Anna0.40.2
Pavel0.80.4
Jan00.8
Mario0.40.4
Luigi0.20.3
Euclidean distance from Anna
userdistancewatched M3
Mario0.2000
Luigi0.2240
Pavel0.447 
Jan0.721 
Evidence, $k = 2$
$$\text{M3 evidence} = \tfrac{1}{2}(0 + 0) = 0$$
attributes: evidence 1  ·  completion profiles: evidence 0
The representation changed the neighbours, not the evidence about M3.

User-based k-NN: The Algorithm

Algorithm: user-based k-NN, implicit feedback
Input: completion matrix $X$, $B_{ij} = \mathbf{1}[X_{ij} > 0]$, user $i$, number of neighbours $k$, similarity $\mathrm{sim}$
representation1. profile $\textcolor{#2e7d32}{\mathbf{h}_i = (X_{i1}, X_{i2})}$ for every user
similarity2. $\textcolor{#1f5fbf}{s_l = \mathrm{sim}(\mathbf{h}_i, \mathbf{h}_l)}$ for every eligible $l \neq i$
similarity3. $\mathcal{N}_k(i) \leftarrow$ the $k$ users with the largest $s_l$
aggregation4. $\textcolor{#b26a00}{\mathrm{score}(i, j) = \tfrac{1}{k} \sum_{l \in \mathcal{N}_k(i)} B_{lj}}$ for each candidate $j$
Neighbours first
Choose neighbours independently of candidate $j$: do not restrict them to users who watched $j$.
For now
Here $\mathrm{sim} = 1/(1 + d)$, and the unweighted average is intentional at this stage. Evidence uses presence $B_{lj}$, not the completion fraction.

The Recipe of a k-NN Recommender

Every k-NN recommender is defined by three choices.

1 · Representation
Which vector describes a user or an item?
2 · Similarity
How close are two vectors?
3 · Aggregation
How many neighbours, and how do we combine them?

Which differences in behaviour should make two users less similar?

Does Similarity Depend on Perception?

AB
Question
Which square is darker, A or B?
Join them with a band of their own colour.
Without the context, they are the same grey.
Our eyes judge similarity by context. A recommender cannot: we must define it.

Similarity from Implicit Feedback

Recall
No recorded interaction does not establish a negative preference.
Implicit feedback
$B_{ij} = 1$ if an interaction was recorded. Each user is a set of items, $\Omega^i = \{j : (i,j) \in \Omega\}$.
A separate binary example with four users, not Anna's cohort.
$\Omega^1$1 3 4 8 12 15 17 24 35 39 41 43$|\Omega^1| = 12$
$\Omega^2$2 3 4 5 9 12 13 16 19 24 27 31$|\Omega^2| = 12$
$\Omega^3$4 5 9 12$|\Omega^3| = 4$
$\Omega^4$4 9$|\Omega^4| = 2$
$\Omega^3$ as a binary row, items 1 to 12:
123456789101112
000110001001
A first idea
$$\mathrm{sim}(i, l) = |\Omega^i \cap \Omega^l|, \quad \text{the number of items in common}$$

Intersection as Similarity

$\Omega^2$
$\Omega^1$
$\Omega^3$
$\Omega^4$
123458912131516171924273135394143
$\mathrm{sim}(1,2) = |\Omega^1 \cap \Omega^2| = 4$
$\mathrm{sim}(2,3) = |\Omega^2 \cap \Omega^3| = 4$
$\mathrm{sim}(3,4) = |\Omega^3 \cap \Omega^4| = 2$
Question
Should sharing four items always count more than sharing two?

More Activity, More Overlap

In pairs
Discuss with a colleague: in terms of recommendation, is it reasonable that
$\mathrm{sim}(1,2) = 4$,   $\mathrm{sim}(2,3) = 4$,   $\mathrm{sim}(3,4) = 2$ ?
Users 1 and 2 interacted with many items. More activity creates more opportunities for overlap.
Activity
useritems $|\Omega^i|$
user 112
user 212
user 34
user 42
$\Omega^4 \subset \Omega^3$: all of user 4's items are shared with user 3

Jaccard Similarity

Definition
$$\mathrm{Jaccard}(i, l) = \frac{|\Omega^i \cap \Omega^l|}{|\Omega^i \cup \Omega^l|} \in [0, 1]$$
$0$: no item in common. $\;1$: exactly the same items. Defined for non-empty sets.
$\Omega^2$
$\Omega^1$
$\Omega^3$
$\Omega^4$
123458912131516171924273135394143
Our four users
pair$\cap$$\cup$Jaccard
$(1,2)$4200.20
$(1,3)$2140.14
$(1,4)$1130.08
$(2,3)$4120.33
$(2,4)$2120.17
$(3,4)$240.50
Is it more reasonable now?
Users 3 and 4 are now the most similar pair.
paircountJaccard
$(1,2)$40.20
$(2,3)$40.33
$(3,4)$20.50

Cosine on Binary Profiles

Two item-presence axes: each user is a vector from the origin.

011item 1item 245°90°A = (1, 0)B = (1, 1)C = (0, 1)
Cosine similarity
$$\cos(\mathbf{x}, \mathbf{y}) = \frac{\mathbf{x}^\top \mathbf{y}}{\|\mathbf{x}\|\,\|\mathbf{y}\|}$$
Three illustrative users
$\cos(A, B) = \dfrac{1}{1 \cdot \sqrt{2}} = 0.707$
$\cos(A, C) = \dfrac{0}{1 \cdot 1} = 0$
For binary vectors
$$\cos = \frac{\text{overlap}}{\sqrt{\text{profile size}_x \cdot \text{profile size}_y}}$$

Cosine on Completion Profiles

Back to Anna's completion profiles: the same coordinates as before.

00.50.511M1 completionM2 completion18°PavelAnnaMarioLuigiJan
cosine with Anna $= (0.4, 0.2)$
userprofilecosine
Pavel(0.8, 0.4)1.000
Mario(0.4, 0.4)0.949
Luigi(0.2, 0.3)0.868
Jan(0, 0.8)0.447
Why is Pavel first?
Same angle as Anna: twice her completions, the same proportions. The distance between the points does not matter.
Cosine preserves relative proportions but ignores overall magnitude.

Euclidean on the Same Coordinates

Same scatter, same scale: now measure straight-line distance from Anna.

00.50.511M1 completionM2 completionAnnaPavelJanMarioLuigi
Euclidean, from Anna
user$d$ES $= 1/(1+d)$
Mario0.2000.833
Luigi0.2240.817
Pavel0.4470.691
Jan0.7210.581
Same points, $k = 2$
Cosine: Pavel, MarioEuclidean: Mario, Luigi
Similar proportions and similar magnitudes are different notions of similarity.

Some Interactions Can Be More Informative

An interaction that everyone has says little about whose taste is close.

completion profiles
userM1M2
Anna0.40.2
Pavel0.80.4
Jan00.8
Mario0.40.4
Luigi0.20.3
every listed user has an M2 interaction
Reweight the features
$$\mathbf{h}' = D\,\mathbf{h}, \qquad D = \mathrm{diag}(1,\; 0.2)$$
illustrative weights
Anna
$(0.4,\; 0.2) \;\longrightarrow\; (0.4,\; 0.04)$
not applied to the later running calculations
Downweight frequent features before comparing profiles.

Is High Similarity Enough?

Two independent pairs of users
paircosineshared interactions
pair A1.002
pair B≈ 0.90100
Which estimate has more evidence?
Support
$$q_{il} = |\Omega^i \cap \Omega^l|$$
the number of items both users interacted with. Use $\mathrm{sim}(i,l)$ only when $q_{il} \geq q_{\min}$, checked before the final neighbour selection.
$q_{\min} = 5$: pair A excluded, pair B retained

Cosine Similarity: Likes and Dislikes

Beyond sets
A set only says whether a user interacted.
Many recommenders also know how: a like, a dislike, a rating.
like $= +1$, dislike $= -1$, unobserved $= 0$
Definition
$$\cos(\mathbf{x}_i, \mathbf{x}_l) = \frac{\mathbf{x}_i^\top \mathbf{x}_l}{\|\mathbf{x}_i\|\,\|\mathbf{x}_l\|}$$
Users as vectors
userMovie 1Movie 2
Anna0+1
Pavel+1−1
Jan+10
Mario−10
Luigi+1+1
−1−111Movie 1Movie 2AnnaPavelJanMarioLuigi180°45°90°
Cosine
paircosine
Jan, Mario−1.00opposite
Anna, Luigi0.71shared like
Anna, Jan0.00no overlap

Choosing a Similarity

Which similarity for which data
datasimilaritywhat it compares
Binary historiesCosine or Jaccarddifferent normalisations of the overlap
Nonnegative weighted historiesCosinecompares relative patterns
Likes and dislikes, $\pm 1$Cosinecan be negative: opposite opinions
Numeric features where magnitude mattersEuclideancheck feature scales first
Feature weighting and support rules are additional choices.

Same Data, Different Neighbours

00.50.511M1 completionM2 completionAnnaPavelJanMarioLuigi
Your turn
Which two users are Anna's neighbours?
Euclidean
Mario, Luigi: closest points
Cosine
Pavel, Mario: closest directions
Optional: binarise
Anna, Pavel, Mario and Luigi all become $(1, 1)$, so Jaccard ties them. This changes the representation as well as the metric.
A neighbourhood encodes a particular meaning of similar behaviour.

The Recipe of a k-NN Recommender

Every k-NN recommender is defined by three choices.

1 · Representation
Which vector describes a user or an item?
2 · Similarity
How close are two vectors?
3 · Aggregation
How many neighbours, and how do we combine them?
completion profiles  |  cosine  |  $k = 2$  |  Pavel and Mario

How much should each neighbour contribute?

Weighted Evidence

Similarity-weighted average
$$\mathrm{score}(i, j) = \frac{\sum_{l \in \mathcal{N}_k(i)} \mathrm{sim}(i, l)\, B_{lj}}{\sum_{l \in \mathcal{N}_k(i)} \mathrm{sim}(i, l)}$$
$$\mathrm{score}(i, j) = \frac{\sum_{l \in \mathcal{N}_k(i)} \textcolor{#1f5fbf}{\mathrm{sim}(i, l)}\, \textcolor{#c2102f}{B_{lj}}}{\sum_{l \in \mathcal{N}_k(i)} \mathrm{sim}(i, l)}$$
$$\mathrm{score}(i, j) = \frac{\sum_{l \in \mathcal{N}_k(i)} \textcolor{#1f5fbf}{\mathrm{sim}(i, l)}\, \textcolor{#c2102f}{B_{lj}}}{\textcolor{#1f5fbf}{\sum_{l \in \mathcal{N}_k(i)} \mathrm{sim}(i, l)}}$$
The denominator is the total similarity of all $k$ neighbours, the same for every candidate.
Anna and M3, neighbours Pavel and Mario
neighbour $l$$\cos(\text{Anna}, l)$$B_{l3}$product
Pavel1.00011.000
Mario0.94900
$\mathrm{score}(\text{Anna}, \text{M3}) = \phantom{\dfrac{\textcolor{#1f5fbf}{1.000} \cdot \textcolor{#c2102f}{1} + \textcolor{#2e7d32}{0.949} \cdot \textcolor{#b26a00}{0}}{\textcolor{#1f5fbf}{1.000} + \textcolor{#2e7d32}{0.949}} = 0.513}$
$\mathrm{score}(\text{Anna}, \text{M3}) = \dfrac{\textcolor{#1f5fbf}{1.000} \cdot \textcolor{#c2102f}{1} \phantom{+ \textcolor{#2e7d32}{0.949} \cdot \textcolor{#b26a00}{0}}}{\phantom{\textcolor{#1f5fbf}{1.000} + \textcolor{#2e7d32}{0.949}}}\phantom{ = 0.513}$
$\mathrm{score}(\text{Anna}, \text{M3}) = \dfrac{\textcolor{#1f5fbf}{1.000} \cdot \textcolor{#c2102f}{1} + \textcolor{#2e7d32}{0.949} \cdot \textcolor{#b26a00}{0}}{\phantom{\textcolor{#1f5fbf}{1.000} + \textcolor{#2e7d32}{0.949}}}\phantom{ = 0.513}$
$\mathrm{score}(\text{Anna}, \text{M3}) = \dfrac{\textcolor{#1f5fbf}{1.000} \cdot \textcolor{#c2102f}{1} + \textcolor{#2e7d32}{0.949} \cdot \textcolor{#b26a00}{0}}{\textcolor{#1f5fbf}{1.000} + \textcolor{#2e7d32}{0.949}} = 0.513$

From Scores to a Ranking

Should Movie 3 or Movie 4 come first?

1 · Anna’s neighbours, cosine
user$\cos(\text{Anna}, l)$
Pavel1.000
Mario0.949
Luigi0.868
Jan0.447
$k = 2$: Pavel and Mario
2 · Score every movie
moviePavelMarioscore
M1111.000watched
M2111.000watched
M3100.513candidate
M4010.487candidate
M1 and M2 score highest, but Anna has already watched them
rank the candidates: M3 (0.513) before M4 (0.487)
top-$N$, $N = 1$: recommend M3

Choosing k

overfittingunderfitting0.20.40.60.8125102050100k (number of neighbours)errorvalidationbest k = 12test
Small $k$: overfitting
With $k = 1$ a single neighbour decides: the prediction copies itself.
Large $k$: underfitting
$k$ = all: everyone gets the same prediction.
Validation
Hold out observed ratings; choose the $k$ with the lowest error.

Neighbours Can Be Movies

User-based
Compare rows: users described by the items they watched.
Item-based
Compare columns: movies described by the users who watched them.
Item similarities built from two historical users: Pavel and Mario
reference userM1M2M3M4
Pavel0.80.410
Mario0.40.401
Anna’s candidates
00.50.511Pavel's completionMario's completionM1M2M3M4

Item-based Aggregation

00.50.511Pavel's completionMario's completion0.8940.7070.4470.707M1M2M3M4
Item-based aggregation
Anna's history weights:  M1: $\textcolor{#1f5fbf}{0.4}$,  M2: $\textcolor{#2e7d32}{0.2}$
$$\mathrm{score}(\text{Anna}, j) = \frac{\sum_{t \in \text{history}} X_{\text{Anna}, t}\; \mathrm{sim}(t, j)}{\sum_{t \in \text{history}} \mathrm{sim}(t, j)}$$
$\text{M3}: \; \dfrac{\textcolor{#1f5fbf}{0.4} \cdot 0.894 + \textcolor{#2e7d32}{0.2} \cdot 0.707}{0.894 + 0.707} = 0.312$
$\text{M4}: \; \dfrac{\textcolor{#1f5fbf}{0.4} \cdot 0.447 + \textcolor{#2e7d32}{0.2} \cdot 0.707}{0.447 + 0.707} = 0.277$
rank: M3 before M4
User-based: combine neighbours' interactions. Item-based: combine related items from the user's history.

User-based vs Item-based in Practice

user-baseditem-based
compared objectsuser profiles: rowsitem profiles: columns
full pairwise$O(m^2)$$O(n^2)$
stabilitya user's row changes with every clickan item's audience changes slowly: precompute offline
stored neighbourhoodsneighbours per user; they change as users actneighbours per item: precomputed item relationships
online evidence aggregationaverage the neighbours' interactions with each candidateaverage over the items in the user's current history
explanation“people with similar histories watched this”“related to what you watched”

Do We Compare Every Pair?

Item-based CF with $n = 100\,000$ items. What do we keep in memory?

Full item × item matrix
n itemsn items
$10^{10}$ similarities  ·  40 GB
Top-$K$ neighbours, $K = 100$
Kn itemseach item: its Kmost similar items
$10^{7}$ similarities  ·  40 MB
Storing only $K$ neighbours saves memory, but we still have to find them.

How Do We Find Neighbours?

1 · Exhaustive
Compare all eligible pairs and keep the nearest. The dense matrix does not have to stay in memory.
exact, $O(n^2)$ comparisons
2 · Sparse co-occurrence
Compare only pairs that share interactions, using sparse operations or an inverted index.
exact, fewer pairs
3 · Approximate search
query
An index walks a neighbour graph to the likely neighbours, without scanning every vector.
fast, approximate
No training, but…
OFFLINEbuild neighbourhoodsONLINEretrieve candidatesscorerank

Cold Start

userM1M2M3M4M5 (new)
Anna0.40.2000
Pavel0.80.4100
Jan00.80.700
Mario0.40.4010
Luigi0.20.300.60
Eva (new)00000
0 = no recorded history, not a negative opinion
New user
Eva has just signed up: her row has no recorded history. Her profile $(0, 0)$ has zero norm, so cosine is undefined.
New item
M5 has just been released: its column has no recorded history. M4 is not new: it was already a ranking candidate.
No history vs. weak support
No history: nothing to compare. A few interactions: we can compare, but the support is weak.

Who Can Still Recommend?

00.50.511actiondramaM1M2M3M4M5 (new)
Content-based rescue for M5
Attributes exist from day one: $\mathbf{b}_{5} = (0.9, 0.1)$.
movieES to M5Pavel completion
M30.8761
M20.6390.4
M10.5030.8
M40.4690 (not watched)
neighbours come from all movies; unwatched ones add 0
score(Pavel, M5): $\dfrac{1 \cdot 0.876 + 0.4 \cdot 0.639}{0.876 + 0.639} \approx 0.747$
a score, not stars or a probability
Caveat
Item attributes alone do not identify a completely new user's preferences: onboarding, context or a non-personalised fallback is still needed.

What If Feedback Is Explicit?

Everything so far used implicit feedback. Many systems also collect ratings.

So far: implicit
A watch was recorded or not; a zero means no record, not a dislike.
Now: explicit
A rating says how much a user liked an item, and a missing rating is unknown, not zero.
Three new questions
Which items do we compare? Do users rate alike?
How do we predict a rating?

Which Items Do We Compare?

Explicit ratings are also partially observed. How similar are Anna and Pavel?

12345678Movie
Anna
3121?0?012
Pavel
534?0?053415
Option 1 · fill with zero
Treating missing entries as observed zeros invents rating values.
Missing ratings are not observed ratings.
Option 2 · co-rated items only
Compare only $I_{il} = \Omega^i \cap \Omega^l$, the movies both rated.
the standard choice for explicit feedback

Haters vs Lovers

On their co-rated movies (M1, M2, M3, M7, M8), Anna rates low and Pavel rates high.

Co-rated ratings
userM1M2M3M7M8mean
Anna312121.8
Pavel534343.8
Minus each user's mean
userM1M2M3M7M8
Anna+1.2−0.8+0.2−0.8+0.2
Pavel+1.2−0.8+0.2−0.8+0.2
identical rows: same taste, a different scale
Pearson correlation
$$\mathrm{sim}(i, l) = \frac{\sum_{j \in I_{il}} (X_{ij} - \mu_i)(X_{lj} - \mu_l)}{\sqrt{\sum_{j \in I_{il}} (X_{ij} - \mu_i)^2}\,\sqrt{\sum_{j \in I_{il}} (X_{lj} - \mu_l)^2}}$$
$\mu_i$: mean of user $i$ on $I_{il}$. Pearson is the cosine of the mean-centred co-rated vectors: here it equals $1.00$.

Mean-centred Prediction

Remove each user's scale, then add Anna's back
$$\hat{X}_{ij} = \mu_i + \frac{\sum_{l \in \mathcal{N}_k(i,j)} \mathrm{sim}(i, l)\, (X_{lj} - \mu_l)}{\sum_{l \in \mathcal{N}_k(i,j)} \mathrm{sim}(i, l)}$$
$\mu_i$: the mean of user $i$'s observed ratings.
Anna and Movie 3, $k = 2$
user $l$$\mathrm{ES}$$X_{l3}$$\mu_l$$X_{l3} - \mu_l$
AnnaNA?4.50NA
Mario0.5013.00−2.00
Luigi0.4123.67−1.67
$\hat{X}_{\text{Anna},3} = \textcolor{#2e7d32}{4.50} + \phantom{\dfrac{\textcolor{#1f5fbf}{0.50} \cdot \textcolor{#c2102f}{(-2.00)} + \textcolor{#1f5fbf}{0.41} \cdot \textcolor{#c2102f}{(-1.67)}}{\textcolor{#1f5fbf}{0.50} + \textcolor{#1f5fbf}{0.41}} = 2.65}$
$\hat{X}_{\text{Anna},3} = \textcolor{#2e7d32}{4.50} + \dfrac{\textcolor{#1f5fbf}{0.50} \cdot \textcolor{#c2102f}{(-2.00)} + \textcolor{#1f5fbf}{0.41} \cdot \textcolor{#c2102f}{(-1.67)}}{\phantom{\textcolor{#1f5fbf}{0.50} + \textcolor{#1f5fbf}{0.41}}}\phantom{ = 2.65}$
$\hat{X}_{\text{Anna},3} = \textcolor{#2e7d32}{4.50} + \dfrac{\textcolor{#1f5fbf}{0.50} \cdot \textcolor{#c2102f}{(-2.00)} + \textcolor{#1f5fbf}{0.41} \cdot \textcolor{#c2102f}{(-1.67)}}{\textcolor{#1f5fbf}{0.50} + \textcolor{#1f5fbf}{0.41}} = 2.65$
Why higher than 1.45?
Mario and Luigi rated Movie 3 about two points below their own means. Anna is a generous rater ($\mu_{\text{Anna}} = 4.50$).
the haters vs lovers idea, now in the prediction

k-NN for Recommendation: Pros and Cons

Strengths
✓no training: the data is the model, so new interactions are used without retraining
✓explainable: “users like you liked it” or “because you liked Movie 2”
✓flexible: neighbours from interactions or attributes
✓reusable: item neighbourhoods change slowly: precompute offline, reuse online
✓strong baseline: well-tuned k-NN is still competitive with many recent neural recommenders (Ferrari Dacrema et al., RecSys 2019)
Limitations
✗many choices: the similarity, $k$ and the weighting all change the prediction
✗sparsity: few co-rated items give high similarity with weak evidence (low coverage)
✗scale: exact search needs $O(n^2)$ comparisons; fast search is approximate
✗cold start: collaborative filtering has no neighbours for new users or items
CTU logo
NIE-PML · CTU FIT

Obrigado!

Questions?