+ All Categories
Home > Technology > A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Date post: 11-Apr-2017
Category:
Upload: codemotion
View: 51 times
Download: 2 times
Share this document with a friend
100
Transcript
Page 1: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17
Page 2: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

A recommendation engine for your apps

Page 3: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17
Page 4: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Definition: a system that help people finding things when the process of finding what you need is challenging because you have a lot of choices/alternatives

Page 5: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

So… it’s a search engine!

Page 6: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Search Engines

Document base is (almost) static

Queries are dynamic

Page 7: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Search Engines

Create an index analysing the documents

Calculate relevance for a query: tf*idf

Page 8: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Recommender systems

Document base is growing (eg: Netflix)

Query is static: find something I like

Page 9: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Classification

Page 10: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Domain: news, products, …

Helps defining what can be suggested

Page 11: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Purpose: sales, information, education, build a community

What is TripAdvisor purpose?

Page 12: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Personalisation levels

• Non personalised: best sellers

• Demographic: age, location

• Ephemeral: based on current activities

• Persistent

Page 13: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Types of input

• Explicit: ask user to rate something

• Implicit: inferred from user behaviour

Page 14: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Output

• Prediction: predicted rating, evaluation

• Recommendations: suggestion list, top-n, offers, promotion

• Filtering: email filters, news articles

Page 15: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

A model for comparison

Page 16: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

User: people with preference

Items: subject of rating

Rating: expression of opinion

(Community: space where opinions makes sense)

Page 17: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17
Page 18: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Non personalised

Page 19: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Best seller

Most popular

Trending

Summary of community ratings: eg best hotel in town

Page 20: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17
Page 21: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17
Page 22: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Hotel

Page 23: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Visitor Hotel

Page 24: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Visitor Hotel

Page 25: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Hotel A Hotel B Hotel C

John 3 5

Jane 3

Fred 1 0

Tom 4

AVG 3.5 3 0

Page 26: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Content based

Page 27: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

User rate items

We build a model of user preference

Look for similar items based on the model

Page 28: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17
Page 29: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Action 0.7

Sci Fi 3.2

Vin Diesel 1.2

… …

https://www.amazon.com/Relevant-Search-applications-Solr-Elasticsearch/dp/161729277Xhttp://www.slideshare.net/treygrainger/building-a-real-time-solrpowered-recommendation-engine

Page 30: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Problems/Limitations

Page 31: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Need to know items content

User cold start: time to learn important features for the user

What if user interest change?

Lack of serendipity: accidentally discover something you like

Page 32: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Collaborative filtering

Page 33: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

No need to analyse (index) content

Can capture more subtle things

Serendipity

Page 34: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

User-User

Select people of my neighbourhood with similar taste. If other people share my taste I want their opinion combined

Page 35: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

E.T

2 4Joe 2 2 3 ?

1 55 2 4 …

Tom 3 3 2

4 1

User-User: which users have similar tastes?

Page 36: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

E.T

2 4Joe 2 2 3 ?

1 55 2 4 …

Tom 3 3 2

4 1

User-User: which users have similar tastes?

Page 37: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Item-Item

Find an items where I have expressed an opinion and look how other people felt about it. Precompute similarities between items

Page 38: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

E.T

2 4Joe 2 2 3 ?

1 55 2 4 …

Tom 3 3

4 1

Item-Item: which item are similar?

Page 39: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Problems/Limitations

Page 40: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Sparsity

When recommending from a large item set, users will have rated only some of the items

Page 41: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

User Cold start

Not enough known about new user to decide who is similar

Page 42: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Item cold start

Cannot predict ratings for new item till some similar users have rated it [No problem for content-based]

Page 43: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Scalability

With millions of ratings, computations become slow

Dimensionality reduction FTW!

Page 44: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

An example

Page 45: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Item1 Item2 Item3 Item4 Item5

Joe 8 1 ? 2 7

Tom 2 ? 5 7 5

Alice 5 4 7 4 7

Bob 7 1 7 3 8

How similar are Joe and Tom? How similar are Joe and Bob?

Page 46: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Only consider items both users have rated

For each item - Compute difference in the users’ ratings - Take the average of this difference over the items

Item1 Item2 Item3 Item4 Item5

Joe 8 1 ? 2 7

Tom 2 ? 5 7 5

Alice 5 4 7 4 7

Bob 7 1 7 3 8

Page 47: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Sim(Joe, Tom) = (|8-2| + |2-7| + |7-5|)/3 = 13/3 = 4.3

Sim(Joe, Alice) = (|8-5| + |1-4| + |2-4| + |7-7|)/4 = 2

Sim(Joe, Bob) = (|8-7| + |1-1| + |2-3| + |7-8|)/4 = 0.75

Item1 Item2 Item3 Item4 Item5

Joe 8 1 ? 2 7

Tom 2 ? 5 7 5

Alice 5 4 7 4 7

Bob 7 1 7 3 8

Page 48: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Similarity

Bob 0.75

Alice 2

Tom 4.3

D = 1 / 1 + d

Page 49: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Similarity

Bob 1.57

Alice 0.33

Tom 0.18

D = 1 / 1 + d

Page 50: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Recommend what similar user have rated highly

To calculate rating of an item to recommend, give weight to each user’s recommendations based on how similar they are to you.

Page 51: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Rating(Joe, Item3) = (1.57 * 7 + 0.33 * 7 + 0.18 * 5) / 3

10.99 + 2.31 + 0.9 / 3 = 4.3

Similarity

Bob 1.57

Alice 0.33

Tom 0.18

Page 52: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

use entire matrix or

use a K-nn algorithm: people who historically have the same tastes as me

aggregate using weighted sum

weights depends on similarity

Page 53: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Cosine similarity

[3,5]

[2,7]

[0,0]

Page 54: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Our domain

Page 55: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Domain: online book shop, both paper and digital

Recommend titles, old and new

- Who bought this also bought

- You might like

Page 56: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Choosing the tool

Page 57: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

PredictionIO

Page 58: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Under the Apache umbrella

Based on solid open source stack

Customisable templates engines

SDK for PHP

Page 59: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17
Page 60: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Installation

http://actionml.com/docs/pio_by_actionml

Pre-baked Amazon AMIs

Page 61: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Installation via source code

http://predictionio.incubator.apache.org/install/install-sourcecode/

Page 62: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

You can choose storage

mysql/postgres vs elasticsearch+hbase

Page 63: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

The event server

Page 64: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17
Page 65: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Pattern: user -- action -- item

User 1 purchased product X

User 2 viewed product Y

User 1 added product Z in the cart

Page 66: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

$ pio app new MyApp1

[INFO] [App$] Initialized Event Store for this app ID: 1. [INFO] [App$] Created new app: [INFO] [App$] Name: MyApp1 [INFO] [App$] ID: 1 [INFO] [App$] Access Key: 3mZWDzci2D5YsqAnqNnXH9SB6Rg3dsTBs8iHkK6X2i54IQsIZI1eEeQQyMfs7b3F

$ pio eventserver

Page 67: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Server runs on port 7070 by default

$ curl -i -X GET http://localhost:7070

{“status":"alive"}

Page 68: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

$ curl -i -X GET “http://localhost:7070/events.json?accessKey=$ACCESS_KEY"

Page 69: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Events modeling

what can/should we model?

rate, like, buy, view, depending on the algorithm

Page 70: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17
Page 71: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17
Page 72: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17
Page 73: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

setUser($uid, array $properties=array(), $eventTime=null)

unsetUser($uid, array $properties, $eventTime=null)

deleteUser($uid, $eventTime=null)

setItem($iid, array $properties=array(), $eventTime=null)

unsetItem($iid, array $properties, $eventTime=null)

deleteItem($iid, $eventTime=null)

recordUserActionOnItem($event, $uid, $iid, array $properties=array(), $eventTime=null)

createEvent(array $data)

getEvent($eventId)

Page 74: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Engines

Page 75: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17
Page 76: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

D.A.S.E Architecture

Data Source and Preparation

Algorithm

Serving

Evaluation

Page 77: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

$ pio template get apache/incubator-predictionio-template-recommender MyRecommendation

$ cd MyRecommendation

Page 78: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

engine.json

"datasource": { "params" : { "appName": “MyApp1”, "eventNames": [“buy”, “view”] } },

Page 79: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

$ pio build —verbose

$ pio train

$ pio deploy

Page 80: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Getting recommendations

Page 81: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17
Page 82: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17
Page 83: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17
Page 84: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Implementation

Page 85: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17
Page 86: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

2 kind of suggestions

- who bought this also bought (recommendation)

- you may like (similarities)

Page 87: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

View

Like (add to basket, add to wishlist)

Conversion (buy)

Recorded in batch

Page 88: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

4 engines

2 for books, 2 for ebooks

(not needed now)

Retrained every night with new data

Page 89: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

recordLike($user, array $item)

recordConversion($user, array $item)

recordView($user, array $item)

createUser($uid)

Page 90: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

getRecommendation($uid, $itype, $n = self::N_SUGGESTION)

getSimilarity($iid, $itype, $n = self::N_SUGGESTION)

Page 91: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17
Page 92: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

user cold start/item cold start

if we don’t get enough suggestion switch to non personalised (also for non logged users)

Page 93: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17
Page 94: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Alternative approaches

Page 95: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

https://github.com/grahamjenson/list_of_recommender_systems

Page 96: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17
Page 97: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Do it on your own

https://github.com/grahamjenson/ger

Page 98: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

https://neo4j.com/developer/guide-build-a-recommendation-engine/

Page 99: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Michele Orselli CTO@Ideato

_orso_

micheleorselli / ideatosrl

[email protected]

Page 100: A recommendation engine for your applications - M.Orselli - Codemotion Rome 17

Links• http://www.slideshare.net/NYCPredictiveAnalytics/building-a-recommendation-

engine-an-example-of-a-product-recommendation-engine?next_slideshow=1

• https://www.coursera.org/learn/recommender-systems-introduction

• http://actionml.com/

• https://github.com/grahamjenson/ger


Recommended