stanford university - mining of massive … ·  · 2014-08-111 3 4 3 5 5 4 5 5 3 3 2 2 2 5 2 1 1 3...

58
Mining of Massive Datasets Jure Leskovec, Anand Rajaraman, Jeff Ullman Stanford University http://www.mmds.org Note to other teachers and users of these slides: We would be delighted if you found this our material useful in 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

Upload: vuthuan

Post on 26-Apr-2018

216 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

Mining of Massive Datasets

Jure Leskovec, Anand Rajaraman, Jeff Ullman Stanford University

http://www.mmds.org

Note to other teachers and users of these slides: We would be delighted if you found this our

material useful in 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: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

� 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

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 2

Page 3: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

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

3J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org

Matrix R

Page 4: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

1 3 4

3 5 5

4 5 5

3

3

2 ? ?

?

2 1 ?

3 ?

1

Test Data Set

RMSE = �� ∑ �̂�� ��� ��,� ∈�

4

480,000 users

17,700 movies

Predicted rating

True rating of

user x on item i

��,�Matrix R

Training Data Set

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org

Page 5: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

� 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

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 5

Global effects

Factorization

Collaborative filtering

Page 6: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

� 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

� Local neighborhood (CF/NN):

� Joe didn’t like related movie Signs

� ⇒⇒⇒⇒ Final estimate:

Joe will rate The Sixth Sense 3.8 stars

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 6

Page 7: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

� Earliest and most popular collaborative

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

7J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org

∑∑

∈⋅

=);(

);(ˆ

xiNj ij

xiNj xjij

xis

rsr sij… similarity of items i and j

rxj…rating of user x on item j

N(i;x)… set of items similar to

item i that were rated by x

Page 8: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

� In practice we get better estimates if we

model deviations:

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 8

µ = overall mean rating

bx = 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

restricting

Solution: Instead of sij use wij that

we estimate directly from data

^

∑∑

∈−⋅

+=

);(

);()(

xiNj ij

xiNj xjxjij

xixis

brsbr

baseline estimate for rxi

��� � � � �� � ��

Page 9: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

� 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)

� We allow: ∑ !�" # $"∈ ��,� � !�" models interaction between pairs of movies

(it does not depend on user x)J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 9

Page 10: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

� ���� � ��� � ∑ ��� ��� ����∈���,� � How to set wij?

� Remember, error metric is:�� ∑ �̂�� ��� ��,� ∈�

or equivalently SSE: ∑ �%�� ��� &��,� ∈'� 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

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 10

Why is this a good idea?

Page 11: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

� 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 set build a system such that it works well

on known (user, item) ratings

And hope the system will also predict well the

unknown ratings

11J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org

1 3 4

3 5 5

4 5 5

3

3

2 2 2

5

2 1 1

3 3

1

Page 12: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

� 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 vector of numbers

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 12

Predicted ratingTrue

rating

Page 13: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

� A simple way to minimize a function )�� :� Compute the take a derivative*)� Start at some point + and evaluate *)�+ � Make a step in the reverse direction of the

gradient: + � + *)�+ � Repeat until converged

13

,

-

, - � .,�-

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org

Page 14: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

� We have the optimization problem, now what?

� Gradient decent:

� Iterate until convergence: ! ← ! η*!0� where *!0is the gradient (derivative evaluated on data):

.1( �2(�� 2��� � 2� ��� � � ��4 ��4 ��4

4∈� �;� ��� ��� ���

�,�for " ∈ 5 �; � , ∀�, ∀�7else

89�1 81:; � <

� Note: We fix movie i, go over all rxi, for every movie " ∈ �; � , we compute

=0�! =!�"

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 14

ηηηη … learning rate

while |wnew - wold| > ε:

wold = wnew

wnew = wold - ηηηη ·∇∇∇∇wold

( � �� ��� � � ��� ��� ����∈� �;�

���

Page 15: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

� So far: ���� � ��� � ∑ ��� ��� ����∈���;� � Weights wij derived based

on their role; no use of an

arbitrary similarity measure

(wij ≠ sij)

� Explicitly account for

interrelationships among

the neighboring movies

� Next: Latent factor model

� Extract “regional” correlations

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 15

Global effects

Factorization

CF/NN

Page 16: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

Grand Prize: 0.8563

Netflix: 0.9514

Movie average: 1.0533

User average: 1.0651

Global average: 1.1296

Basic Collaborative filtering: 0.94

CF+Biases+learned weights: 0.91

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 16

Page 17: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

Geared

towards

females

Geared

towards

males

Serious

Funny17J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org

The PrincessDiaries

The Lion King

Braveheart

Lethal Weapon

Independence Day

AmadeusThe Color Purple

Dumb and Dumber

Ocean’s 11

Sense and Sensibility

Page 18: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

� “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 will want the reconstruction error to be small on known

ratings and we don’t care about the values on the missing ones

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 18

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

users

ite

ms

PT

Q

item

s

users

R

SVD: A = U Σ VT

factors

facto

rs

Page 19: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

� How to estimate the missing rating of

user x for item i?

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 19

45531

312445

53432142

24542

522434

42331

ite

ms

.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

ite

ms

users

users

?

PT

�%�� � >� ⋅ @���>�) ⋅ @�)

)qi = row i of Q

px = column x of PT

facto

rs

Qfactors

Page 20: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

� How to estimate the missing rating of

user x for item i?

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 20

45531

312445

53432142

24542

522434

42331

ite

ms

.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

ite

ms

users

users

?

PT

facto

rs

Qfactors

�%�� � >� ⋅ @���>�) ⋅ @�)

)qi = row i of Q

px = column x of PT

Page 21: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

� How to estimate the missing rating of

user x for item i?

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 21

45531

312445

53432142

24542

522434

42331

ite

ms

.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

ite

ms

users

users

?

Q

PT

2.4

ffa

cto

rs

f factors

�%�� � >� ⋅ @���>�) ⋅ @�)

)qi = row i of Q

px = column x of PT

Page 22: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

Geared

towards

females

Geared

towards

males

Serious

Funny22J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org

The PrincessDiaries

The Lion King

Braveheart

Lethal Weapon

Independence Day

AmadeusThe Color Purple

Dumb and Dumber

Ocean’s 11

Sense and Sensibility

Factor 1

Fa

cto

r 2

Page 23: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

Geared

towards

females

Geared

towards

males

Serious

Funny23J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org

The PrincessDiaries

The Lion King

Braveheart

Lethal Weapon

Independence Day

AmadeusThe Color Purple

Dumb and Dumber

Ocean’s 11

Sense and Sensibility

Factor 1

Fa

cto

r 2

Page 24: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

� Remember SVD:

� A: Input data matrix

� U: Left singular vecs

� V: Right singular vecs

� ΣΣΣΣ: Singular values

� So in our case:

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

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

AAAAm

n

ΣΣΣΣm

n

VVVVTTTT

24

UUUU

�%�� � >� ⋅ @�J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org

Page 25: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

� We already know that SVD gives minimum

reconstruction error (Sum of Squared Errors):

minD,E,F � G�� HΣJK ��

��∈L� Note two things:

� SSE and RMSE are monotonically related:

� 'MNO � $P NNO Great news: SVD is minimizing RMSE

� Complication: The sum in SVD error term is over

all entries (no-rating in interpreted as zero-rating).

But our R has missing entries!25J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org

Page 26: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

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

� minQ,R ∑ ��� S� ⋅ T� �,� ∈�

� Note:

� We don’t require cols of P, Q to be orthogonal/unit length

� P, Q map users/movies to a latent space

� The most popular model among Netflix contestantsJ. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 26

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

PT

Q

users

ite

ms

�̂�� � S� ⋅ T�

factors

facto

rsite

ms

users

Page 27: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of
Page 28: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

� Our goal is to find P and Q such tat:

U�VW,X � ��� >� ⋅ @� &

�,� ∈'

28

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

PT

Q

users

ite

ms

factors

facto

rsite

ms

users

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org

Page 29: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

� 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 it fits too well the training data and thus not

generalizing well to unseen test data

29

1 3 43 5 5

4 5 533

2 ? ??

2 1 ?3 ?

1

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org

Page 30: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

� To solve overfitting we introduce

regularization:

� Allow rich model where there are sufficient data

� Shrink aggressively where data are scarce

30

++− ∑∑∑

i

i

x

x

training

xixi

QP

qppqr2

2

2

1

2

,

)(min λλ

1 3 43 5 5

4 5 533

2 ? ??

2 1 ?3 ?

1

λλλλ1, λλλλ2 … user set regularization parameters

“error” “length”

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

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org

Page 31: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

Geared

towards

females

Geared

towards

males

serious

funny31J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org

The PrincessDiaries

The Lion King

Braveheart

Lethal Weapon

Independence Day

AmadeusThe Color Purple

Dumb and Dumber

Ocean’s 11

Sense and Sensibility

Factor 1

Fa

cto

r 2

minfactors “error” + λ “length”

++− ∑∑∑

i

i

x

x

training

xixi

QP

qppqr222

,

)(min λ

Page 32: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

Geared

towards

females

Geared

towards

males

serious

funny32J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org

The Lion King

Braveheart

Lethal Weapon

Independence Day

AmadeusThe Color Purple

Dumb and Dumber

Ocean’s 11

Sense and Sensibility

Factor 1

Fa

cto

r 2

The PrincessDiaries

minfactors “error” + λ “length”

++− ∑∑∑

i

i

x

x

training

xixi

QP

qppqr222

,

)(min λ

Page 33: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

Geared

towards

females

Geared

towards

males

serious

funny33J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org

The Lion King

Braveheart

Lethal Weapon

Independence Day

AmadeusThe Color Purple

Dumb and Dumber

Ocean’s 11

Sense and Sensibility

Factor 1

Fa

cto

r 2

minfactors “error” + λ “length”

The PrincessDiaries

++− ∑∑∑

i

i

x

x

training

xixi

QP

qppqr222

,

)(min λ

Page 34: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

Geared

towards

females

Geared

towards

males

serious

funny34J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org

The Lion King

Braveheart

Lethal Weapon

Independence Day

AmadeusThe Color Purple

Dumb and Dumber

Ocean’s 11

Sense and Sensibility

Factor 1

Fa

cto

r 2

The PrincessDiaries

minfactors “error” + λ “length”

++− ∑∑∑

i

i

x

x

training

xixi

QP

qppqr222

,

)(min λ

Page 35: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

� Want to find matrices P and Q:

� Gradient decent:

� Initialize P and Q (using SVD, pretend missing ratings are 0)

� Do gradient descent:

� P ←←←← P - ηηηη ·∇∇∇∇P

� Q ←←←← Q - ηηηη ·∇∇∇∇Q

� where ∇∇∇∇Q is gradient/derivative of matrix Q:

.Y � Z.S�[\ and .S�[ � ∑ 2 ��� S�T� T�[�,� � 2]S�[� Here >�) is entry f of row qi of matrix Q

� Observation: Computing gradients is slow!J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 35

How to compute gradient

of a matrix?

Compute gradient of every

element independently!

++− ∑∑∑

i

i

x

x

training

xixi

QP

qppqr2

2

2

1

2

,

)(min λλ

Page 36: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

� Gradient Descent (GD) vs. Stochastic GD

� Observation: .Y � Z.S�[\ where

.S�[ ��2 ��� S�[T�[ T�[�,�

� 2]S�[ ��∇X�,�

���� Here >�) is entry f of row qi of matrix Q

� X � X η∇X � X η ∑ ∇X�,� ���� � Idea: Instead of evaluating gradient over all ratings

evaluate it for each individual rating and make a step

� GD: X←X η ∑ ∇X���� ���� SGD: X←X ^∇X����

� Faster convergence!� Need more steps but each step is computed much faster

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 36

Page 37: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

� Convergence of GD vs. SGD

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 37

Iteration/step

Valu

e o

f th

e o

bje

cti

ve f

un

cti

on

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 step

takes much longer to

compute.

In practice, SGD is

much faster!

Page 38: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

� Stochastic gradient decent:

� 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���� S� ⋅ T� (derivative of the “error”)

� S� ← S� � ^� _��T� ]S� (update equation)

� T� ← T� � ^ _��S� ]�T� (update equation)

� 2 for loops:� For until convergence:

� For each rxi

� Compute gradient, do a “step”J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 38

^ … learning rate

Page 39: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

Koren, Bell, Volinksy, IEEE Computer, 200939J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org

Page 40: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of
Page 41: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 41

� μ = 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 42: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

� 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”)

42J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org

Page 43: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

� Example:

� Mean rating: µ µ µ µ = 3.7

� You are a critical reviewer: your ratings are 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

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 43

Overall

mean rating

Bias for

user x

Bias for

movie i

�� � � � �User-Movie

interaction

Page 44: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

� Solve:

� Stochastic gradient decent to find parameters

� Note: Both biases bx, bi as well as interactions qi, px

are treated as parameters (we estimate them)

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 44

regularization

goodness of fit

λ is selected via grid-

search on a validation set

( )

++++

+++−

∑∑∑∑

∑∈

i

i

x

x

x

x

i

i

Rix

xiixxi

PQ

bbpq

pqbbr

2

4

2

3

2

2

2

1

2

),(,

)(min

λλλλ

µ

Page 45: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

45

0.885

0.89

0.895

0.9

0.905

0.91

0.915

0.92

1 10 100 1000

RM

SE

Millions of parameters

CF (no time bias)

Basic Latent Factors

Latent Factors w/ Biases

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org

Page 46: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

Grand Prize: 0.8563

Netflix: 0.9514

Movie average: 1.0533

User 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

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 46

Page 47: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of
Page 48: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

� 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

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 48

Y. Koren, Collaborative filtering with

temporal dynamics, KDD ’09

Page 49: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

� 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

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 49

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

Page 50: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 50

0.875

0.88

0.885

0.89

0.895

0.9

0.905

0.91

0.915

0.92

1 10 100 1000 10000

RM

SE

Millions of parameters

CF (no time bias)

Basic Latent Factors

CF (time bias)

Latent Factors w/ Biases

+ Linear time factors

+ Per-day user biases

+ CF

Page 51: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

Grand Prize: 0.8563

Netflix: 0.9514

Movie average: 1.0533

User 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

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 51

Latent factors+Biases+Time: 0.876

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

Page 52: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 52

Page 53: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 53

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

Page 54: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

� 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 that they are in direct competition with Ensemble

� Strategy

� Both teams carefully monitoring the leaderboard

� Only sure way to check for improvement is to submit a set of predictions

� This alerts the other team of your latest score

54J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org

Page 55: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

� 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….

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 55

Page 56: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 56

Page 57: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 57

Page 58: Stanford University - Mining of Massive … ·  · 2014-08-111 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 J. Leskovec, A. Rajaraman, J. Ullman: Mining of

� Some slides and plots borrowed from

Yehuda Koren, Robert Bell and Padhraic

Smyth

� Further reading:

� Y. Koren, Collaborative filtering with temporal

dynamics, KDD ’09

� http://www2.research.att.com/~volinsky/netflix/bpc.html

� http://www.the-ensemble.com/

J. Leskovec, A. Rajaraman, J. Ullman: Mining of Massive Datasets, http://www.mmds.org 58