39
© 2014 MapR Technologies © 2014 MapR Technologies 1 Real-time Recommandation: Puppies and Ponies in Motion Onkar Ambekar Data Scientist, EMEA

"Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

Embed Size (px)

Citation preview

Page 1: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies© 2014 MapR Technologies1

Real-time Recommandation: Puppies and Ponies in Motion

Onkar Ambekar Data Scientist, EMEA

Page 2: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 2

Agenda• Background – recommending with puppies and ponies • Speed tricks • Accuracy tricks • Moving to real-time

Page 3: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 3

Puppies and Ponies

Page 4: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 4

Cooccurrence Analysis

Page 5: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 5

How Often Do Items Co-occur

ʹAA

A

Page 6: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 6

Which Co-occurrences are Interesting?

Each row of indicators becomes a field in a search engine document

ʹAA

sparsify ʹAA( )

Page 7: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 7

Recommendations

Alice got an apple and a puppyAlice

Page 8: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 8

Recommendations

Alice got an apple and a puppyAlice

Charles got a bicycleCharles

Page 9: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 9

Recommendations

Alice got an apple and a puppyAlice

Charles got a bicycleCharles

Bob Bob got an apple

Page 10: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 10

Recommendations

Alice got an apple and a puppyAlice

Charles got a bicycleCharles

Bob What else would Bob like?

Page 11: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 11

Recommendations

Alice got an apple and a puppyAlice

Charles got a bicycleCharles

Bob A puppy!

Page 12: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 12

By the way, like me, Bob also wants a pony…

Page 13: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 13

Recommendations

?

Alice

Bob

Charles

Amelia

What if everybody gets a pony?

What else would you recommend for new user Amelia?

Page 14: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 14

Recommendations

?

Alice

Bob

Charles

AmeliaIf everybody gets a pony, it’s not a very good indicator of what to else predict...

Page 15: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 15

Problems with Raw Co-occurrence

• Very popular items co-occur with everything or why it’s not very helpful to know that everybody wants a pony… – Examples: Welcome document; Elevator music

• Very widespread occurrence is not interesting to generate indicators for recommendation – Unless you want to offer an item that is constantly desired, such as

razor blades (or ponies) • What we want is anomalous co-occurrence

– This is the source of interesting indicators of preference on which to base recommendation

Page 16: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 16

Overview: Get Useful Indicators from Behaviors

1. Use log files to build history matrix of users x items – Remember: this history of interactions will be sparse compared to all

potential combinations 2. Transform to a co-occurrence matrix of items x items 3. Look for useful indicators by identifying anomalous co-occurrences to

make an indicator matrix – Log Likelihood Ratio (LLR) can be helpful to judge which co-

occurrences can with confidence be used as indicators of preference – ItemSimilarityJob in Apache Mahout uses LLR

Page 17: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 17

Which one is the anomalous co-occurrence?

A not AB 13 1000

not B 1000 100,000

A not AB 1 0

not B 0 10,000

A not AB 10 0

not B 0 100,000

A not AB 1 0

not B 0 2

Page 18: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 18

Which one is the anomalous co-occurrence?

A not AB 13 1000

not B 1000 100,000

A not AB 1 0

not B 0 10,000

A not AB 10 0

not B 0 100,000

A not AB 1 0

not B 0 20.90 1.95

4.52 14.3

Dunning Ted, Accurate Methods for the Statistics of Surprise and Coincidence, Computational Linguistics vol 19 no. 1 (1993)

Page 19: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 19

Collection of Documents: Insert Meta-Data

Search EngineItem

meta-data

Document for “puppy”

id: t4 title: puppy desc: The sweetest little puppy ever. keywords: puppy, dog, pet

Ingest easily via NFS

✔indicators: (t1)

Page 20: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 20

Cooccurrence Mechanics• Cooccurrence is just a self-join for each user, i for each history item j1 in Ai* for each history item j2 in Ai*

count pair (j1, j2)

aij1aij2 = ʹAAi∑

Page 21: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 21

Cross-occurrence Mechanics• Cross occurrence is just a self-join of adjoined matrices for each user, i for each history item j1 in Ai* for each history item j2 in Bi*

count pair (j1, j2)

aij1bij2 = ʹABi∑ A |B[ ] A |B[ ]= ʹAA ʹAB

ʹBA ʹBB⎡

⎣⎢

⎦⎥

Page 22: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 22

A word about scaling

Page 23: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 23

A few pragmatic tricks• Downsample all user histories to max length (interaction cut)

– Can be random or most-recent (no apparent effect on accuracy) – Prolific users are often pathological anyway – Common limit is 300 items (no apparent effect on accuracy)

• Downsample all items to limit max viewers (frequency limit) – Can be random or earliest (no apparent effect) – Ubiquitous items are uninformative – Common limit is 500 users (no apparent effect)

Schelter, et al. Scalable similarity-based neighborhood methods with MapReduce. Proceedings of the sixth ACM conference on Recommender systems. 2012

Page 24: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 24

But note!• Number of pairs for a user history with ki distinct items is ≈ ki

2/2 • Average size of user history increases with increasing dataset

– Average may grow more slowly than N (or not!) – Full cooccurrence cost grows strictly faster than N

– i.e. it just doesn’t scale • Downsampling interactions places bounds on per user cost

– Cooccurrence with interaction cut is scalable

t∝ ki2i∑ ∈ o(N)

t∝ min kmax2 ,ki2( )< Nkmax2i∑ ∈O(N)

Page 25: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 25

0 200 400 600 800 1000

01

23

45

6

Benefit of down−sampling

User Limit

Pairs

(x 1

09 )Without down−sampling

Track limit = 1000

500

200

Computed on 48,373,586 pair−wise tr iplesfrom the million song dataset

Page 26: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 26

Batch Scaling in Time Implies Scaling in Space• Note:

– With frequency limit sampling, max cooccurrence count is small (<1000) – With interaction cut, total number of non-zero pairs is relatively small – Entire cooccurrence matrix can be stored in memory in ~10-15 GB

• Specifically: – With interaction cut, cooccurrence scales in size

– Without interaction cut, cooccurrence does not scale size-wiseʹAA

0∈O(N)

ʹAA0∈ω(N)

Page 27: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 27

Impact of Interaction Cut Downsampling• Interaction cut allows batch cooccurrence analysis to be O(N) in

time and space • This is intriguing

– Amortized cost is low – Could this be extended to an on-line form?

• Incremental matrix factorization is hard – Could cooccurrence be a key alternative?

• Scaling matters most at scale – Cooccurrence is very accurate at large scale – Factorization shows benefits at smaller scales

Page 28: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 28

Online update

Page 29: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 29

Requirements for Online Algorithms• Each unit of input must require O(1) work

– Theoretical bound

• The constants have to be small enough on average – Pragmatic constraint

• Total accumulated data must be small (enough) – Pragmatic constraint

Page 30: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 30

Log Files

Search Technology

Item Meta-Data

via NFS

MapR Cluster

via NFS PostPre

Recommendations

New User History

Web Tier

Recommendations happen in real-time

Batch co-occurrence

Want this to be real-time

Real-time recommendations using MapR data platform

Page 31: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 31

Space Bound Implies Time Bound• Because user histories are pruned, only a limited number of value

updates need be made with each new observation

• This bound is just twice the interaction cut kmax

– Which is a constant

• Bounding the number of updates trivially bounds the time

Page 32: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 32

Implications for Online Update

A+eij( )ʹ A+eij( )− ʹAA= eij A+ ʹAeij +δ jj

=0Ai*0

⎢⎢⎢

⎥⎥⎥+ 0 Ai*( ) 0⎡

⎣⎢

⎦⎥+δ jj

Page 33: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 33

Ai* + Ai*( ) +δii0

≤ 2kmax −1∈O(1)

With interaction cut at kmax

Page 34: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 34

But Wait, It Gets Better• The new observation may be pruned

– For users at the interaction cut, we can ignore updates – For items at the frequency cut, we can ignore updates – Ignoring updates only affects indicators, not recommendation query – At million song dataset size, half of all updates are pruned

• On average ki is much less than the interaction cut – For million song dataset, average appears to grow with log of frequency

limit, with little dependency on values of interaction cut > 200 • LLR cutoff avoids almost all updates to index • Average grows slowly with frequency cut

Page 35: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 35

0 200 400 600 800 1000

05

1015

2025

3035

Interaction cut (kmax)

k ave

Frequency cut = 1000

= 500

= 200

Page 36: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 36

0 200 400 600 800 1000

05

1015

2025

3035

Frequency cut

k ave

Page 37: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 37

Recap• Cooccurrence-based recommendations are simple

– Deploying with a search engine is even better • Interaction cut and frequency cut are key to batch scalability

• Similar effect occurs in online form of updates – Only dozens of updates per transaction needed – Data structure required is relatively small – Very, very few updates cause search engine updates

• Fully online recommendation is very feasible, almost easy

Page 38: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 38

More Details Available

available for free at

http://www.mapr.com/practical-machine-learning

Page 39: "Real-time Recommendations: Puppies and Ponies in Motion", Onkar Ambekar, Data Scientist, EMEA at MapR

© 2014 MapR Technologies 39

Q & A@mapr maprtech

[email protected]

Engage with us!

MapR

maprtech

mapr-technologies