People who liked this talk also liked … Building Recommendation Systems Using Ruby

51
People who liked this talk also liked … Building Recommendation Systems Using Ruby Ryan Weald, @rweald LA RubyConf 2013 1

description

From Amazon, to Spotify, to thermostats, recommendation systems are everywhere. The ability to provide recommendations for your users is becoming a crucial feature for modern applications. In this talk I'll show you how you can use Ruby to build recommendation systems for your users. You don't need a PhD to build a simple recommendation engine -- all you need is Ruby. Together we'll dive into the dark arts of machine learning and you'll discover that writing a basic recommendation engine is not as hard as you might have imagined. Using Ruby I'll teach you some of the common algorithms used in recommender systems, such as: Collaborative Filtering, K-Nearest Neighbor, and Pearson Correlation Coefficient. At the end of the talk you should be on your way to writing your own basic recommendation system in Ruby.

Transcript of People who liked this talk also liked … Building Recommendation Systems Using Ruby

Page 1: People who liked this talk also liked … Building Recommendation Systems Using Ruby

People who liked this talk also liked … Building Recommendation Systems

Using Ruby

Ryan Weald, @rwealdLA RubyConf 2013

1

Page 2: People who liked this talk also liked … Building Recommendation Systems Using Ruby

Who is this guy?

What does he know about recommendation

systems?

2

Page 3: People who liked this talk also liked … Building Recommendation Systems Using Ruby

Data Scientist @Sharethrough

Native advertising platform

3

Page 4: People who liked this talk also liked … Building Recommendation Systems Using Ruby

4

Page 5: People who liked this talk also liked … Building Recommendation Systems Using Ruby

Outline

1) What is a recommendation system?

2) Collaborative filtering based recommendations

3) Content based recommendations

4) Hybrid systems - the best of both worlds

5) Evaluating your recommendation system

6) Resources & existing libraries

5

Page 6: People who liked this talk also liked … Building Recommendation Systems Using Ruby

What this Talk is Not

• Everything there is to know about recommendation systems.

• Bleeding edge machine learning

• How to use a specific library

6

Page 7: People who liked this talk also liked … Building Recommendation Systems Using Ruby

What is a recommendation system?

7

Page 8: People who liked this talk also liked … Building Recommendation Systems Using Ruby

A program that predictsa user’s preferences using information about the user, other users, and the

items in your system.

8

Page 9: People who liked this talk also liked … Building Recommendation Systems Using Ruby

LinkedIn

9

Page 10: People who liked this talk also liked … Building Recommendation Systems Using Ruby

Netflix

10

Page 11: People who liked this talk also liked … Building Recommendation Systems Using Ruby

Spotify

11

Page 12: People who liked this talk also liked … Building Recommendation Systems Using Ruby

Amazon

12

Page 13: People who liked this talk also liked … Building Recommendation Systems Using Ruby

How do I build recommendations?

13

Page 14: People who liked this talk also liked … Building Recommendation Systems Using Ruby

Two Main Categories of Algorithm

1. Collaborative Filtering (CF)

2. Content Based - Classification

14

Page 15: People who liked this talk also liked … Building Recommendation Systems Using Ruby

Collaborative Filtering

Fill in missing user preferences using similar users or items

15

Page 16: People who liked this talk also liked … Building Recommendation Systems Using Ruby

1. Memory Based - Uses similarity between users or items. Dataset usually kept in memory

2. Model Based - Model generated to “explain” observed ratings

Two Types of CF

16

Page 17: People who liked this talk also liked … Building Recommendation Systems Using Ruby

(User x Item) Matrix + Similarity Function = Top-K most similar users

User Based CF

17

Page 18: People who liked this talk also liked … Building Recommendation Systems Using Ruby

Video 1 Video 2 Video 3 Video 4 Video 5

User 1

User 2

User 3

User 4

User 5

0 1 0 5 0

1 2 1 0 5

2 5 0 0 2

5 4 4 1 1

2 4 ? ? 2

Collaborative Filtering

* 0 denotes not rated

18

Page 19: People who liked this talk also liked … Building Recommendation Systems Using Ruby

Similarity Functions

• Pearson Correlation Coefficient

• Cosine Similarity

19

Page 20: People who liked this talk also liked … Building Recommendation Systems Using Ruby

Pearson Correlation Coefficient

20

Page 21: People who liked this talk also liked … Building Recommendation Systems Using Ruby

Calculating PCC

21

Page 22: People who liked this talk also liked … Building Recommendation Systems Using Ruby

Calculating PCC

22

Page 23: People who liked this talk also liked … Building Recommendation Systems Using Ruby

Calculating PCC

23

Page 24: People who liked this talk also liked … Building Recommendation Systems Using Ruby

Calculating PCC

24

Page 25: People who liked this talk also liked … Building Recommendation Systems Using Ruby

Calculating PCC

25

Page 26: People who liked this talk also liked … Building Recommendation Systems Using Ruby

Calculating PCC

26

Page 27: People who liked this talk also liked … Building Recommendation Systems Using Ruby

27

Page 28: People who liked this talk also liked … Building Recommendation Systems Using Ruby

Using similarity to recommend items

28

Page 29: People who liked this talk also liked … Building Recommendation Systems Using Ruby

Video 1 Video 2 Video 3 Video 4 Video 5

User 1

User 2

User 3

User 4

User 5

0 1 0 5 0

1 2 1 0 5

2 5 0 0 2

5 4 4 1 1

2 4 ? ? 2

Collaborative Filtering

* 0 denotes not rated

29

Page 30: People who liked this talk also liked … Building Recommendation Systems Using Ruby

30

Page 31: People who liked this talk also liked … Building Recommendation Systems Using Ruby

• Cold Start

• Data Sparsity

• Resource expensive

Problems With CF

31

Page 32: People who liked this talk also liked … Building Recommendation Systems Using Ruby

Doesn’t the video content matter for recommendations?

32

Page 33: People who liked this talk also liked … Building Recommendation Systems Using Ruby

Content Based Recommendations

Classify items based on features of the item. Pick other items from

same class to recommend.

33

Page 34: People who liked this talk also liked … Building Recommendation Systems Using Ruby

Content Based Algorithms

• K-means clustering

• Random Forrest

• Support Vector Machines

• ...

• Insert your favorite ML algorithm

34

Page 35: People who liked this talk also liked … Building Recommendation Systems Using Ruby

Content Based AlgorithmsType ofcontent

Duration MaturityRating

Video 1

Video 2

Video 3

Video 4

Video 5

comedy 60 G

action 120 G

comedy 34 PG-13

romantic 15 R

sports 120 G

35

Page 36: People who liked this talk also liked … Building Recommendation Systems Using Ruby

K-means Clustering

Group items into K clusters. Assign new item to a cluster and

pick items from that cluster

36

Page 37: People who liked this talk also liked … Building Recommendation Systems Using Ruby

K-means Clustering

37

Page 38: People who liked this talk also liked … Building Recommendation Systems Using Ruby

• Unsupervised Learning is hard

• Training data limited or expensive

• Doesn’t take user into account

• Limited by features of content

Problems With Content Based Recommendations

38

Page 39: People who liked this talk also liked … Building Recommendation Systems Using Ruby

Hybrid Recommendations

Combine collaborative filtering with content based algorithm to achieve

greater results

39

Page 40: People who liked this talk also liked … Building Recommendation Systems Using Ruby

Hybrid Recommendations

Content Based Recommender

CF BasedRecommender

Combiner Reco

Input

Input

40

Page 41: People who liked this talk also liked … Building Recommendation Systems Using Ruby

Hybrid Recommendations

41

Page 42: People who liked this talk also liked … Building Recommendation Systems Using Ruby

Hybrid Recommendations

InputCF

RecommenderContent

RecommenderReco

42

Page 43: People who liked this talk also liked … Building Recommendation Systems Using Ruby

Hybrid Recommendations

CFRecommender

Content Recommender

Input Reco

43

Page 44: People who liked this talk also liked … Building Recommendation Systems Using Ruby

Evaluating Recommendation Quality

• Precision vs. Recall

• Clicks

• Click through rate

• Direct user feedback

44

Page 45: People who liked this talk also liked … Building Recommendation Systems Using Ruby

Precision vs. Recall

45

Page 46: People who liked this talk also liked … Building Recommendation Systems Using Ruby

Precision vs. Recall

46

Page 47: People who liked this talk also liked … Building Recommendation Systems Using Ruby

Summary of What We’ve Learned

• Collaborative Filtering using similar users

• Content clustering using k-means

• Combining 2 algorithms to boost quality

• How to evaluate your recommender

47

Page 49: People who liked this talk also liked … Building Recommendation Systems Using Ruby

Resources & Further Reading

• Recommender Systems: An Introduction

• Linden, Greg, Brent Smith, and Jeremy York.

"Amazon. com recommendations: Item-to-item

collaborative filtering."

• Resnick, Paul, et al. "GroupLens: an open architecture

for collaborative filtering of netnews."

• ACM RecSys Conference Proceedings

49

Page 50: People who liked this talk also liked … Building Recommendation Systems Using Ruby

We’re Hiringhttp://bit.ly/str-engineering

50