58
CS246: Mining Massive Datasets Jure Leskovec, Stanford University http://cs246.stanford.edu Note to other teachers and users of these slides: We would be delighted if you found our material useful for giving your own lectures. Feel free to use these slides verbatim, or to modify them to fit your own needs. If you make use of a significant portion of these slides in your own lecture, please include this message, or a link to our web site: http:// www.mmds.org

cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

CS246: Mining Massive DatasetsJure Leskovec, Stanford University

http://cs246.stanford.edu

Note to other teachers and users of these slides: We would be delighted if you found ourmaterial useful for giving your own lectures. Feel free to use these slides verbatim, or to modify them to fit your own needs. If you make use of a significant portion of these slides in your own lecture, please include this message, or a link to our web site: http://www.mmds.org

Page 2: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

¡ Training data§ 100 million ratings, 480,000 users, 17,770 movies§ 6 years of data: 2000-2005

¡ Test data§ Last few ratings of each user (2.8 million)§ Evaluation criterion: Root Mean Square Error (RMSE) =

"|$|∑(',))∈$ �̂�)' − 𝑟)' /

§ Netflix’s system RMSE: 0.9514¡ Competition

§ 2,700+ teams§ $1 million prize for 10% improvement on Netflix

2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets 2

𝑟)': true rating of user x on item i

Page 3: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

Training Data

100 million ratings

Held-Out Data

3 million ratings

1.5m ratings 1.5m ratings

Quiz Set:scoresposted onleaderboard

Test Set:scoresknown onlyto Netflix

Scores used indeterminingfinal winner

Labels only known to NetflixLabels known publicly

2/4/20 3Jure Leskovec, Stanford CS246: Mining Massive Datasets

Page 4: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

1 3 4

3 5 5

4 5 5

3

3

2 2 2

5

2 1 1

3 3

1

480,000 users

17,700 movies

2/4/20 4Jure Leskovec, Stanford CS246: Mining Massive Datasets

Matrix R

Page 5: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

1 3 4

3 5 5

4 5 5

3

3

2 ? ?

?

2 1 ?

3 ?

1

Test Data Set

RMSE = "1

∑(',))∈$ �̂�)' − 𝑟)' /

5

480,000 users

17,700 movies

Predicted rating

True rating of user x on item i

𝒓𝟑,𝟔

Matrix R

Training Data Set

2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

Page 6: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

¡ The winner of the Netflix Challenge¡ Multi-scale modeling of the data:

Combine top level, “regional”modeling of the data, with a refined, local view:§ Global:

§ Overall deviations of users/movies§ Factorization:

§ Addressing “regional” effects§ Collaborative filtering:

§ Extract local patterns

2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets 6

Global effects

Factorization

Collaborative filtering

Page 7: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

¡ Global:§ Mean movie rating: 3.7 stars§ The Sixth Sense is 0.5 stars above avg.§ Joe rates 0.2 stars below avg. Þ Baseline estimation: Joe will rate The Sixth Sense 4 stars§ That is 4 = 3.7+0.5-0.2

¡ Local neighborhood (CF/NN):§ Joe didn’t like related movie Signs§ Þ Final estimate:

Joe will rate The Sixth Sense 3.8 stars2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets 7

Page 8: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

¡ The earliest and the most popularcollaborative filtering method

¡ Derive unknown ratings from those of “similar” movies (item-item variant)

¡ Define similarity measure sij of items i and j¡ Select k-nearest neighbors, compute the rating § N(i; x): items most similar to i that were rated by x

2/4/20 8Jure Leskovec, Stanford CS246: Mining Massive Datasets

åå

Î

Î×

=);(

);(ˆxiNj ij

xiNj xjijxi s

rsr sij… similarity of items i and j

rxj…rating of user x on item jN(i;x)… set of items similar to

item i that were rated by x

Page 9: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

¡ In practice we get better estimates if we model deviations:

2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets 9

μ = overall avg. ratingbx = rating deviation of user x

= (avg. rating of user x) – μbi = (avg. rating of movie i) – μ

Problems/Issues:1) Similarity measures are “arbitrary”2) Pairwise similarities neglect interdependencies among users 3) Taking a weighted average can be restrictingSolution: Instead of sij, use wij that we estimate directly from data

^

åå

Î

Î-×

+=);(

);()(

xiNj ij

xiNj xjxjijxixi s

brsbr

baseline estimate for rxi

𝒃𝒙𝒊 = 𝝁 + 𝒃𝒙 + 𝒃𝒊

Page 10: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

¡ Use a weighted sum rather than weighted avg.:

:𝑟)' = 𝑏)' + <=∈>(';))

𝑤'= 𝑟)= − 𝑏)=

¡ A few notes:§ 𝑵(𝒊; 𝒙) … set of movies rated by user x that are

similar to movie i§ 𝒘𝒊𝒋 is the interpolation weight (some real number)

§ Note, we allow: ∑𝒋∈𝑵(𝒊;𝒙)𝒘𝒊𝒋 ≠ 𝟏

§ 𝒘𝒊𝒋 models interaction between pairs of movies (it does not depend on user x)

2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets 10

Page 11: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

¡ :𝑟)' = 𝑏)' + ∑=∈>(',)) 𝑤'= 𝑟)= − 𝑏)=¡ How to set wij?

§ Remember, error metric is: "$

∑(',))∈$ �̂�)' − 𝑟)' /

or equivalently SSE: ∑(𝒊,𝒙)∈𝑹 G𝒓𝒙𝒊 − 𝒓𝒙𝒊 𝟐

§ Find wij that minimize SSE on training data!§ Models relationships between item i and its neighbors j

§ wij can be learned/estimated based on x and all other users that rated i

2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets 11

Why is this a good idea?

Page 12: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

¡ Goal: Make good recommendations§ Quantify goodness using RMSE:

Lower RMSE Þ better recommendations§ Want to make good recommendations on items

that user has not yet seen. Can’t really do this!

§ Let’s build a system such that it works well on known (user, item) ratingsAnd hope the system will also predict well the unknown ratings

122/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

1 3 43 5 5

4 5 533

2 2 25

2 1 13 3

1

Page 13: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

¡ Idea: Let’s set values w such that they work well on known (user, item) ratings

¡ How to find such values w?¡ Idea: Define an objective function

and solve the optimization problem

¡ Find wij that minimize SSE on training data!

𝐽 𝑤 = <),'∈$

𝑏)' + <=∈> ';)

𝑤'= 𝑟)= − 𝑏)= − 𝑟)'/

¡ Think of w as a matrix of weights2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets 13

Predicted ratingTruerating

Page 14: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

¡ A simple way to minimize a function 𝒇(𝒙):§ Compute the derivative 𝜵𝒇(𝒙)§ Start at some point 𝒚 and evaluate 𝜵𝒇(𝒚)§ Make a step in the reverse direction of the

gradient: 𝒚 = 𝒚 − 𝜵𝒇(𝒚)§ Repeat until convergence

14

𝑓

𝑦

𝑓 𝑦

2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

𝛻𝑓(𝑦)

Page 15: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

¡ We have the optimization problem, now what?

¡ Gradient descent:§ Iterate until convergence: 𝒘 ← 𝒘− h𝜵𝒘𝑱where 𝜵𝒘𝑱 is the gradient (derivative evaluated on data):

𝛻R𝐽 =𝜕𝐽(𝑤)𝜕𝑤'=

= 2 <),'∈$

𝑏)' + <U∈> ';)

𝑤'U 𝑟)U − 𝑏)U − 𝑟)' 𝑟)= − 𝑏)=

for 𝒋 ∈ {𝑵 𝒊; 𝒙 , ∀𝒊, ∀𝒙 }else YZ(R)YR[\

= 𝟎

§ Note: We fix movie i, go over all rxi, for every movie 𝒋 ∈𝑵 𝒊; 𝒙 , we compute 𝝏𝑱(𝒘)𝝏𝒘𝒊𝒋

2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets 15

h … learning rate

while |wnew - wold| > ε: wold= wnewwnew = wold - h ·Ñwold

𝐽 𝑤 = <),'∈$

𝑏)' + <=∈> ';)

𝑤'= 𝑟)= − 𝑏)= − 𝑟)'/

Page 16: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

¡ So far: :𝑟)' = 𝑏)' + ∑=∈>(';)) 𝑤'= 𝑟)= − 𝑏)=§ Weights wij derived based

on their roles; no use of an arbitrary similarity measure (wij¹ sij)

§ Explicitly account for interrelationships among the neighboring movies

¡ Next: Latent factor model§ Extract “regional” correlations

2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets 16

Global effects

Factorization

CF

Page 17: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

Grand Prize: 0.8563

Netflix: 0.9514

Movie average: 1.0533User average: 1.0651

Global average: 1.1296

Basic Collaborative filtering: 0.94CF+Biases+learned weights: 0.91

2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets 17

Page 18: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

Geared towards females

Geared towards males

Serious

Funny2/4/20 18Jure Leskovec, Stanford CS246: Mining Massive Datasets

The PrincessDiaries

The Lion King

Braveheart

Lethal Weapon

Independence Day

AmadeusThe Color Purple

Dumb and Dumber

Ocean’s 11

Sense and Sensibility

Page 19: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

¡ “SVD” on Netflix data: R ≈ Q · PT

¡ For now let’s assume we can approximate the rating matrix R as a product of “thin” Q · PT

§ R has missing entries but let’s ignore that for now!§ Basically, we want the reconstruction error to be small on known

ratings and we don’t care about the values on the missing ones2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets 19

45531

312445

53432142

24542

522434

42331

.2-.4.1

.5.6-.5

.5.3-.2

.32.11.1

-22.1-.7

.3.7-1

-.92.41.4.3-.4.8-.5-2.5.3-.21.1

1.3-.11.2-.72.91.4-1.31.4.5.7-.8

.1-.6.7.8.4-.3.92.41.7.6-.42.1≈

usersite

ms

PT

Q

item

s

users

R

SVD: A = U S VT

factors

factors

Page 20: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

¡ How to estimate the missing rating of user x for item i?

2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets 20

45531

312445

53432142

24542

522434

42331

item

s

.2-.4.1

.5.6-.5

.5.3-.2

.32.11.1

-22.1-.7

.3.7-1

-.92.41.4.3-.4.8-.5-2.5.3-.21.1

1.3-.11.2-.72.91.4-1.31.4.5.7-.8

.1-.6.7.8.4-.3.92.41.7.6-.42.1

item

s

users

users

?

PT

G𝒓𝒙𝒊 = 𝒒𝒊 ⋅ 𝒑𝒙

=<𝒇

𝒒𝒊𝒇 ⋅ 𝒑𝒙𝒇

qi = row i of Qpx = column x of PT

fact

ors

Qfactors

Page 21: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

¡ How to estimate the missing rating of user x for item i?

2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets 21

45531

312445

53432142

24542

522434

42331

item

s

.2-.4.1

.5.6-.5

.5.3-.2

.32.11.1

-22.1-.7

.3.7-1

-.92.41.4.3-.4.8-.5-2.5.3-.21.1

1.3-.11.2-.72.91.4-1.31.4.5.7-.8

.1-.6.7.8.4-.3.92.41.7.6-.42.1

item

s

users

users

?

PT

fact

ors

Qfactors

G𝒓𝒙𝒊 = 𝒒𝒊 ⋅ 𝒑𝒙

=<𝒇

𝒒𝒊𝒇 ⋅ 𝒑𝒙𝒇

qi = row i of Qpx = column x of PT

Page 22: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

¡ How to estimate the missing rating of user x for item i?

2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets 22

45531

312445

53432142

24542

522434

42331

item

s

.2-.4.1

.5.6-.5

.5.3-.2

.32.11.1

-22.1-.7

.3.7-1

-.92.41.4.3-.4.8-.5-2.5.3-.21.1

1.3-.11.2-.72.91.4-1.31.4.5.7-.8

.1-.6.7.8.4-.3.92.41.7.6-.42.1

item

s

users

users

?

QPT

2.4

ffac

tors

f factors

G𝒓𝒙𝒊 = 𝒒𝒊 ⋅ 𝒑𝒙

=<𝒇

𝒒𝒊𝒇 ⋅ 𝒑𝒙𝒇

qi = row i of Qpx = column x of PT

Page 23: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

Geared towards females

Geared towards males

Serious

Funny2/4/20 23Jure Leskovec, Stanford CS246: Mining Massive Datasets

The PrincessDiaries

The Lion King

Braveheart

Lethal Weapon

Independence Day

AmadeusThe Color Purple

Dumb and Dumber

Ocean’s 11

Sense and Sensibility

Factor 1

Fact

or 2

Page 24: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

Geared towards females

Geared towards males

Serious

Funny2/4/20 24Jure Leskovec, Stanford CS246: Mining Massive Datasets

The PrincessDiaries

The Lion King

Braveheart

Lethal Weapon

Independence Day

AmadeusThe Color Purple

Dumb and Dumber

Ocean’s 11

Sense and Sensibility

Factor 1

Fact

or 2

Page 25: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

¡ Remember SVD:§ A: Input data matrix§ U: Left singular vecs§ V: Right singular vecs§ S: Singular values

¡ So in our case: “SVD” on Netflix data: R ≈ Q · PT

A = R, Q = U, PT = S VT

Am

n

Sm

n

VT

»

25

U

G𝒓𝒙𝒊 = 𝒒𝒊 ⋅ 𝒑𝒙

2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

Page 26: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

¡ We already know that SVD gives minimum reconstruction error (Sum of Squared Errors):

mine,f,g

<'=∈h

𝐴'= − 𝑈Σ𝑉m '=/

¡ Note two things:§ SSE and RMSE are monotonically related:

§ 𝑹𝑴𝑺𝑬 = 𝟏𝒄 𝑺𝑺𝑬 Great news: SVD is minimizing RMSE!

§ Complication: The sum in SVD error term is over all entries (no-rating is interpreted as zero-rating). But our R has missing entries!

262/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

Page 27: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

¡ SVD isn’t defined when entries are missing!¡ Use specialized methods to find P, Q

§ minr,s

∑ ',) ∈1 𝑟)' − 𝑞' ⋅ 𝑝)/

§ Note:§ We don’t require cols of P, Q to be orthogonal/unit length§ P, Q map users/movies to a latent space§ This was the most popular model among Netflix contestants

2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets 27

45531

312445

53432142

24542

522434

42331

.2-.4.1

.5.6-.5

.5.3-.2

.32.11.1

-22.1-.7

.3.7-1

-.92.41.4.3-.4.8-.5-2.5.3-.21.1

1.3-.11.2-.72.91.4-1.31.4.5.7-.8

.1-.6.7.8.4-.3.92.41.7.6-.42.1»

PTQ

users

item

s

�̂�)' = 𝑞' ⋅ 𝑝)

factors

factorsitem

s

users

Page 28: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets
Page 29: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

¡ Our goal is to find P and Q such that:

𝒎𝒊𝒏𝑷,𝑸

<𝒊,𝒙 ∈𝑹

𝒓𝒙𝒊 − 𝒒𝒊 ⋅ 𝒑𝒙𝟐

29

45531

312445

53432142

24542

522434

42331

.2-.4.1

.5.6-.5

.5.3-.2

.32.11.1

-22.1-.7

.3.7-1

-.92.41.4.3-.4.8-.5-2.5.3-.21.1

1.3-.11.2-.72.91.4-1.31.4.5.7-.8

.1-.6.7.8.4-.3.92.41.7.6-.42.1»

PTQ

users

item

s

factors

factorsite

ms

users

2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

Page 30: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

¡ Want to minimize SSE for unseen test data¡ Idea: Minimize SSE on training data§ Want large k (# of factors) to capture all the signals§ But, SSE on test data begins to rise for k > 2

¡ This is a classical example of overfitting:§ With too much freedom (too many free

parameters) the model starts fitting noise§ That is, the model fits the training data too well and

is thus not generalizing well to unseen test data

30

1 3 43 5 5

4 5 533

2 ? ??

2 1 ?3 ?

1

2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

Page 31: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

¡ To solve overfitting we introduce regularization:§ Allow rich model where there is sufficient data§ Shrink aggressively where data is scarce

31

úû

ùêë

é++- ååå

ii

xx

trainingxixi

QPqppqr 2

22

12

,)(min ll

1 3 43 5 5

4 5 533

2 ? ??

2 1 ?3 ?

1

l1, l2 … user set regularization parameters

“error” “length”

Note: We do not care about the “raw” value of the objective function,but we care about P,Q that achieve the minimum of the objective

2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

Page 32: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

Geared towards females

Geared towards males

serious

funny2/4/20 32Jure Leskovec, Stanford CS246: Mining Massive Datasets

The PrincessDiaries

The Lion King

Braveheart

Lethal Weapon

Independence Day

AmadeusThe Color Purple

Dumb and Dumber

Ocean’s 11

Sense and Sensibility

Factor 1

Fact

or 2

minfactors “error” + l “length”úû

ùêë

é++- ååå

ii

xx

trainingxixi

QPqppqr 222

,)(min l

Page 33: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

Geared towards females

Geared towards males

serious

funny2/4/20 33Jure Leskovec, Stanford CS246: Mining Massive Datasets

The Lion King

Braveheart

Lethal Weapon

Independence Day

AmadeusThe Color Purple

Dumb and Dumber

Ocean’s 11

Sense and Sensibility

Factor 1

Fact

or 2

The PrincessDiaries

minfactors “error” + l “length”úû

ùêë

é++- ååå

ii

xx

trainingxixi

QPqppqr 222

,)(min l

Page 34: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

Geared towards females

Geared towards males

serious

funny2/4/20 34Jure Leskovec, Stanford CS246: Mining Massive Datasets

The Lion King

Braveheart

Lethal Weapon

Independence Day

AmadeusThe Color Purple

Dumb and Dumber

Ocean’s 11

Sense and Sensibility

Factor 1

Fact

or 2

minfactors “error” + l “length”

The PrincessDiaries

úû

ùêë

é++- ååå

ii

xx

trainingxixi

QPqppqr 222

,)(min l

Page 35: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

Geared towards females

Geared towards males

serious

funny2/4/20 35Jure Leskovec, Stanford CS246: Mining Massive Datasets

The Lion King

Braveheart

Lethal Weapon

Independence Day

AmadeusThe Color Purple

Dumb and Dumber

Ocean’s 11

Sense and Sensibility

Factor 1

Fact

or 2

The PrincessDiaries

minfactors “error” + l “length”úû

ùêë

é++- ååå

ii

xx

trainingxixi

QPqppqr 222

,)(min l

Page 36: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

¡ Want to find matrices P and Q:

¡ Gradient descent:§ Initialize P and Q (using SVD, pretend missing ratings are 0)§ Do gradient descent:

§ P ¬ P - h ·ÑP§ Q ¬ Q - h ·ÑQ§ where ÑQ is gradient/derivative of matrix Q:𝛻𝑄 = [𝛻𝑞'|] and 𝛻𝑞'| = ∑): ),' ∈𝑡𝑟 𝑎 𝑖𝑛 𝑖𝑛 𝑔 −2 𝑟)' − 𝑞'𝑝) 𝑝)| + 2𝜆/𝑞'|§ Here 𝒒𝒊𝒇 is entry f of row qi of matrix Q

§ Observation: Computing gradients is slow!2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets 36

How to compute gradient of a matrix?Compute gradient of every element independently!

úû

ùêë

é++- ååå

ii

xx

trainingxixi

QPqppqr 2

22

12

,)(min ll

Page 37: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

¡ Gradient Descent (GD) vs. Stochastic GD§ Observation: 𝛻𝑄 = [𝛻𝑞'|] where𝛻𝑞'| = <

): ),' ∈𝑡 𝑟 𝑎 𝑖𝑛 𝑖𝑛 𝑔−2 𝑟)' − 𝑞'|𝑝)| 𝑝)| + 2𝜆𝑞'| = <

): ),' ∈𝑡 𝑟 𝑎 𝑖𝑛 𝑖𝑛 𝑔Ñ𝑸 𝒓𝒙𝒊

§ Here 𝒒𝒊𝒇 is entry f of row qi of matrix Q

§ 𝑸 ← 𝑸− hÑ𝑸 = 𝑸− h ∑𝒙Ñ𝑸(𝒓𝒙𝒊)§ Idea: Instead of evaluating gradient over all ratings

evaluate it for each individual rating and make a step¡ GD: 𝑸¬𝑸 − h ∑𝒓𝒙𝒊Ñ𝑸(𝒓𝒙𝒊)¡ SGD: 𝑸¬𝑸 − 𝜇Ñ𝑸(𝒓𝒙𝒊)§ Faster convergence!

§ Need more steps but each step is computed much faster2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets 37

Page 38: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

¡ Convergence of GD vs. SGD

2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets 38

Iteration/step

Valu

e of

the

obje

ctiv

e fu

nctio

n

GD improves the value of the objective function at every step. SGD improves the value but in a “noisy” way.GD takes fewer steps to converge but each steptakes much longer to compute. In practice, SGD is much faster!

Page 39: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

¡ Stochastic gradient descent:§ Initialize P and Q (using SVD, pretend missing ratings are 0)

§ Then iterate over the ratings (multiple times if necessary) and update factors:For each rxi:§ 𝜀)' = 2(𝑟)' − 𝑞' ⋅ 𝑝) ) (derivative of the “error”)

§ 𝑞' ← 𝑞' + 𝜇" 𝜀)' 𝑝) − 2𝜆/ 𝑞' (update equation)

§ 𝑝) ← 𝑝) + 𝜇/ 𝜀)' 𝑞' − 2𝜆" 𝑝) (update equation)

¡ Two For loops:§ For until convergence:

§ For each rxi

§ Compute gradient, do a “step” as above2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets 39

𝜇 … learning rate

Page 40: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

Koren, Bell, Volinksy, IEEE Computer, 20092/4/20 40Jure Leskovec, Stanford CS246: Mining Massive Datasets

Page 41: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets
Page 42: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets 42

¡ μ = overall mean rating¡ bx = bias of user x¡ bi = bias of movie i

user-movie interactionmovie biasuser bias

User-Movie interaction¡ Characterizes the matching between

users and movies¡ Attracts most research in the field¡ Benefits from algorithmic and

mathematical innovations

Baseline predictor§ Separates users and movies§ Benefits from insights into user’s

behavior§ Among the main practical

contributions of the competition

Page 43: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

¡ We have expectations on the rating by user x of movie i, even without estimating x’s attitude towards movies like i

– Rating scale of user x– Values of other ratings user

gave recently (day-specific mood, anchoring, multi-user accounts)

– (Recent) popularity of movie i– Selection bias; related to

number of ratings user gave on the same day (“frequency”)

2/4/20 43Jure Leskovec, Stanford CS246: Mining Massive Datasets

Page 44: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

¡ Example:§ Mean rating: µ = 3.7§ You are a critical reviewer: your mean rating is

1 star lower than the mean: bx = -1§ Star Wars gets a mean rating of 0.5 higher than

average movie: bi = + 0.5§ Predicted rating for you on Star Wars:

= 3.7 - 1 + 0.5 = 3.2 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets 44

Overall mean rating

Bias for user x

Bias formovie i

𝑟)' = 𝜇 + 𝑏) + 𝑏' + 𝑞'⋅ 𝑝)User-Movieinteraction

Page 45: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

¡ Solve:

¡ Stochastic gradient descent to find parameters§ Note: Both biases bx, bi as well as interactions qi, px

are treated as parameters (and we learn them)

2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets 45

regularization

goodness of fit

l is selected via grid-search on a validation set

( )

÷ø

öçè

æ++++

+++-

åååå

åÎ

ii

xx

xx

ii

Rixxiixxi

PQ

bbpq

pqbbr

24

23

22

21

2

),(,

)(min

llll

µ

Page 46: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

Grand Prize: 0.8563

Netflix: 0.9514

Movie average: 1.0533User average: 1.0651

Global average: 1.1296

Basic Collaborative filtering: 0.94

Latent factors: 0.90

Latent factors+Biases: 0.89

Collaborative filtering++: 0.91

2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets 46

Page 47: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets
Page 48: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

¡ Sudden rise in the average movie rating(early 2004)§ Improvements in Netflix§ GUI improvements§ Meaning of rating changed

¡ Movie age§ Users prefer new movies

without any reasons§ Older movies are just

inherently better than newer ones

2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets 48

[Y. Koren, Collaborative filtering with temporal dynamics, KDD ’09]

Page 49: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

¡ Original model:rxi = µ +bx + bi + qi ·px

¡ Add time dependence to biases:rxi = µ +bx(t)+ bi(t) +qi · px§ Make parameters bx and bi to depend on time§ (1) Parameterize time-dependence by linear trends

(2) Each bin corresponds to 10 consecutive weeks

¡ Add temporal dependence to factors§ px(t)… user preference vector on day t

2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets 49Y. Koren, Collaborative filtering with temporal dynamics, KDD ’09

Page 50: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

Grand Prize: 0.8563

Netflix: 0.9514

Movie average: 1.0533User average: 1.0651

Global average: 1.1296

Basic Collaborative filtering: 0.94

Latent factors: 0.90

Latent factors+Biases: 0.89

Collaborative filtering++: 0.91

2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets 50

Latent factors+Biases+Time: 0.876

Still no prize! LGetting desperate.Try a “kitchen sink” approach!

Page 51: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets 51

Page 52: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets 52

June 26th submission triggers 30-day “last call”

Page 53: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

¡ Ensemble team formed§ Group of other teams on leaderboard forms a new team§ Relies on combining their models§ Quickly also get a qualifying score over 10%

¡ BellKor§ Continue to get small improvements in their scores§ Realize they are in direct competition with team Ensemble

¡ Strategy§ Both teams carefully monitoring the leader board§ Only sure way to check for improvement is to submit a set

of predictions§ This alerts the other team of your latest score

2/4/20 53Jure Leskovec, Stanford CS246: Mining Massive Datasets

Page 54: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

¡ Submissions limited to 1 a day§ Only 1 final submission could be made in the last 24h

¡ 24 hours before deadline…§ BellKor team member in Austria notices (by chance) that

Ensemble posts a score that is slightly better than BellKor’s

¡ Frantic last 24 hours for both teams§ Much computer time on final optimization§ Carefully calibrated to end about an hour before deadline

¡ Final submissions§ BellKor submits a little early (on purpose), 40 mins before

deadline§ Ensemble submits their final entry 20 mins later§ ….and everyone waits….

2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets 54

Page 55: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets 55

Page 56: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets 56

Page 57: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets 57

What’s the moral of the story?

Submit early! J

Page 58: cs246.stanfordweb.stanford.edu/class/cs246/slides/08-recsys2.pdf¡In practice we get better estimates if we model deviations: 2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets

¡ Some slides and plots borrowed from Yehuda Koren, Robert Bell and PadhraicSmyth

¡ Further reading:§ Y. Koren, Collaborative filtering with temporal

dynamics, KDD ’09¡ https://web.archive.org/web/20141130213501/http://www2.research.at

t.com/~volinsky/netflix/bpc.html¡ https://web.archive.org/web/20141227110702/http://www.the-

ensemble.com/

2/4/20 Jure Leskovec, Stanford CS246: Mining Massive Datasets 58