SlideShare a Scribd company logo
A recommendation
engine
for your PHP apps
1) Intro to recommender systems
2) PredictionIO
3) Case Study
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
So… it’s a search engine!
Search Engines
Document base is (almost) static
Queries are dynamic
Search Engines
Create an index analyzing the
documents
Calculate relevance for a query: tf*idf
Recommender systems
Document base is growing (eg: Netflix)
Query is static: find something I like
Classification
Domain: news, products, …
Helps defining what can be suggested
Purpose: sales, information, education,
build a community
What is TripAdvisor purpose?
Personalization levels
• Non personalized: best sellers
• Demographic: age, location
• Ephemeral: based on current activities
• Persistent
Types of input
• Explicit: ask user to rate something
• Implicit: inferred from user behaviour
Output
• Prediction: predicted rating,
evaluation
• Recommendations: suggestion list,
top-n, offers, promotion
• Filtering: email filters, news articles
A model for comparison
User: people with preference
Items: subject of rating
Rating: expression of opinion
(Community: space where opinions
makes sense)
A recommendation engine for your php application
Non-personalized
Best seller
Most popular
Trending
Summary of community ratings: eg best
hotel in town
A recommendation engine for your php application
A recommendation engine for your php application
Hotel
Visitor Hotel
Visitor Hotel
Hotel A Hotel B Hotel C
John 3 5
Jane 3
Fred 1 0
Tom 4
AVG 3.5 3 0
Content based
User rate items
We build a model of user preference
Look for similar items based on the
model
A recommendation engine for your php application
Action 0.7
Sci Fi 3.2
Vin Diesel 1.2
… …
https://www.amazon.com/Relevant-Search-applications-Solr-Elasticsearch/dp/161729277X
http://www.slideshare.net/treygrainger/building-a-real-time-solrpowered-recommendation-engine
Problems/Limitations
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
Collaborative filtering
No need to analyze (index) content
Can capture more subtle things
Serendipity
User-User
Select people of my neighborhood with
similar taste. If other people share my
taste I want their opinion combined
E.T
2 4
Joe 2 2 3 ?
1 5
5 2 4 …
Tom 3 3 2
4 1
User-User: which users have similar tastes?
E.T
2 4
Joe 2 2 3 ?
1 5
5 2 4 …
Tom 3 3 2
4 1
User-User: which users have similar tastes?
Item-Item
Find an items where I have expressed
an opinion and look how other people
felt about it. Precompute similarities
between items
E.T
2 4
Joe 2 2 3 ?
1 5
5 2 4 …
Tom 3 3
4 1
Item-Item: which item are similar?
Problems/Limitations
Sparsity
When recommending from a large item
set, users will have rated only some of
the items
User Cold start
Not enough known about new user to
decide who is similar
Item cold start
Cannot predict ratings for new item till
some similar users have rated it [No
problem for content-based]
Scalability
With millions of ratings, computations
become slow
Dimensionality reduction
Express my opinions as a set of tastes
Compact representation of the matrix
with relevant features
Rogue
One
1
3
5
Joe 1 2 3
An example
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?
Only consider items both users have rated
For each item
- Calculate 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
Sim(Joe, Tom) = (|8-2| + |2-7| + |7-5|)/3 = 13/3 = 4.3
	 	 	 	 	 	
Sim(Alice, Bob) = (|5-7| + |4-1| + |4-3| + |7-8|)/4 =
7/4 = 1.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
Now we have a score or weight for
each user
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.
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
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 Item1 and Item2?
How similar are Item1 and Item3?
Only consider items both users have rated
For each item
- Calculate difference in ratings for the 2 items
- Take the average of this difference over the users
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
Sim(I1, I2) = (|8-1| + |5-4| + |7-1|)/3 = 14/3 = 4,6
Sim(I1, I3) = (|2-5| + |5-7| + |7-7|)/3 = 5/3 = 1,6
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
As user-user, use whole matrix or identify neighbors
Cosine similarity
[3,5]
[2,7]
[0,0]
Our domain
Domain: online book shop, both paper
and digital
Recommend titles, old and news
- Who bought this also bought
- You might like
Choosing the tool
PredictionIO
Under the Apache umbrella
Based on solid open source stack
Customizable templates engines
SDK for PHP
A recommendation engine for your php application
Installation
http://actionml.com/docs/pio_by_actionml
Pre-baked Amazon AMIs
Installation via source code
http://predictionio.incubator.apache.org/
install/install-sourcecode/
You can choose storage
mysql/postgres vs elasticsearch+hbase
The event server
A recommendation engine for your php application
Pattern: user -- action -- item
User 1 purchased product X
User 2 viewed product Y
User 1 added product Z in the cart
$ 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
Server runs on port 7070 by default
$ curl -i -X GET http://localhost:7070
{“status":"alive"}
$ curl -i -X GET “http://localhost:7070/
events.json?accessKey=$ACCESS_KEY"
Events modeling
what can/should we model?
rate, like, buy, view, depending on the
algorithm
A recommendation engine for your php application
A recommendation engine for your php application
A recommendation engine for your php application
$set , $unset and $delete
_pio* are reserved
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)
Engines
A recommendation engine for your php application
D.A.S.E Architecture
Data Source and Preparation
Algorithm
Serving
Evaluation
$ pio template get apache/
incubator-predictionio-template-
recommender MyRecommendation
$ cd MyRecommendation
engine.json
"datasource": {

"params" : {

"appName": “MyApp1”,

"eventNames": [“buy”, “view”]
}

},
$ pio build —verbose
$ pio train
$ pio deploy
Getting recommendations
A recommendation engine for your php application
A recommendation engine for your php application
A recommendation engine for your php application
Implementation
A recommendation engine for your php application
2 kind of suggestions
- who bought this also bought
(recommendation)
- you may like (similarities)
View
Like (add to basket, add to wishlist)
Conversion (buy)
Recorded in batch
4 engines
2 for books, 2 for ebooks
(not needed now)
Retrained every night with new data
recordLike($user, array $item)
recordConversion($user, array $item)
recordView($user, array $item)
createUser($uid)
getRecommendation($uid, $itype, $n =
self::N_SUGGESTION)
getSimilarity($iid, $itype, $n =
self::N_SUGGESTION)
A recommendation engine for your php application
user cold start/item cold start
if we don’t get enough suggestion
switch to non personalized (also for
non logged users)
A recommendation engine for your php application
user cold start/item cold start
if we don’t get enough suggestion
switch to non personalized (best
sellers)
Michele Orselli
CTO@Ideato
_orso_
micheleorselli / ideatosrl
mo@ideato.it
https://joind.in/talk/93d2d
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

More Related Content

PDF
Recommendation System Explained
PDF
Anatomy of an eCommerce Search Engine by Mayur Datar
PDF
Monitoring Microservices
PPTX
Question Answering System using machine learning approach
PPTX
Sentiment analysis
PDF
Project report
PPTX
Sentiment Analysis using Twitter Data
DOCX
[[Srs]] online shopping website for TYBSC IT
Recommendation System Explained
Anatomy of an eCommerce Search Engine by Mayur Datar
Monitoring Microservices
Question Answering System using machine learning approach
Sentiment analysis
Project report
Sentiment Analysis using Twitter Data
[[Srs]] online shopping website for TYBSC IT

What's hot (20)

PPTX
Movie recommendation Engine using Artificial Intelligence
PPTX
Social media mining PPT
PDF
Online News Portal System
PPT
Sentiment analysis in Twitter on Big Data
PDF
SRS For Online Store
PDF
Chat Application [Full Documentation]
PPTX
Online Shopping System [SE]
PDF
Music Recommendation 2018
PPTX
Salesforce administrator training presentation slides
PPTX
Super Market Management System
PPTX
Recommendation Engine Project Presentation
PDF
Class Management System Project Proposal
PPTX
SRS Of Social Networking
PDF
Recommender Systems
PDF
Complete Guide To Salesforce Einstein Analytics
PDF
Canteen automation system (updated) revised
PDF
Notepad Testing Report
DOCX
Online grocery store
PPTX
Recommender systems for E-commerce
DOCX
A research on- Sales force Project- documentation
Movie recommendation Engine using Artificial Intelligence
Social media mining PPT
Online News Portal System
Sentiment analysis in Twitter on Big Data
SRS For Online Store
Chat Application [Full Documentation]
Online Shopping System [SE]
Music Recommendation 2018
Salesforce administrator training presentation slides
Super Market Management System
Recommendation Engine Project Presentation
Class Management System Project Proposal
SRS Of Social Networking
Recommender Systems
Complete Guide To Salesforce Einstein Analytics
Canteen automation system (updated) revised
Notepad Testing Report
Online grocery store
Recommender systems for E-commerce
A research on- Sales force Project- documentation
Ad

Viewers also liked (20)

PDF
Learn To Test Like A Grumpy Programmer - 3 hour workshop
PDF
Dip Your Toes in the Sea of Security
ODP
My app is secure... I think
PDF
Beyond Design Patterns and Principles - PHPBenelux 2017
PDF
Functional Structures in PHP
PDF
Tactical DDD (just better OOP?) - PHPBenelux 2017
PPTX
Php extensions
PDF
SunshinePHP 2017 - Making the most out of MySQL
PPTX
Debugging Effectively - SunshinePHP 2017
PDF
Code Coverage for Total Security in Application Migrations
PPTX
Debugging Effectively - PHP UK 2017
PDF
JWT - To authentication and beyond!
PDF
PHP UK 2017 - Don't Lose Sleep - Secure Your REST
PDF
Hopping in clouds - phpuk 17
PPTX
Docker for Developers - Sunshine PHP
PDF
WordPress for the modern PHP developer
PDF
Extreme automation
ODP
Abstract Symfony2 CMF
PDF
Symfony e micro (non così tanto) services
PDF
Please understand me
Learn To Test Like A Grumpy Programmer - 3 hour workshop
Dip Your Toes in the Sea of Security
My app is secure... I think
Beyond Design Patterns and Principles - PHPBenelux 2017
Functional Structures in PHP
Tactical DDD (just better OOP?) - PHPBenelux 2017
Php extensions
SunshinePHP 2017 - Making the most out of MySQL
Debugging Effectively - SunshinePHP 2017
Code Coverage for Total Security in Application Migrations
Debugging Effectively - PHP UK 2017
JWT - To authentication and beyond!
PHP UK 2017 - Don't Lose Sleep - Secure Your REST
Hopping in clouds - phpuk 17
Docker for Developers - Sunshine PHP
WordPress for the modern PHP developer
Extreme automation
Abstract Symfony2 CMF
Symfony e micro (non così tanto) services
Please understand me
Ad

Similar to A recommendation engine for your php application (20)

PDF
A recommendation engine for your applications - M.Orselli - Codemotion Rome 17
PDF
A recommendation engine for your applications phpday
PDF
A recommendation engine for your applications codemotion ams
PDF
A recommendation engine for your applications - Michele Orselli- Codemotion A...
PDF
Collaborative Filtering 1: User-based CF
PDF
Introduction to recommender systems
PDF
PPT
Item based approach
PDF
PPT by Jannach_organized.pdf presentation on the recommendation
PDF
Recommender Systems and Linked Open Data
PPTX
Introduction to Recommendation System
PPTX
Lecture Notes on Recommender System Introduction
PPTX
Recommendation Systems Roadtrip
PPT
Digital Trails Dave King 1 5 10 Part 2 D3
PDF
Overview of recommender system
PDF
Recsys 2016
PPTX
Recommenders Systems
PPTX
Recommended System.pptx
PPTX
Recommendation Systems
PDF
Introduction to Recommendation Systems (Vietnam Web Submit)
A recommendation engine for your applications - M.Orselli - Codemotion Rome 17
A recommendation engine for your applications phpday
A recommendation engine for your applications codemotion ams
A recommendation engine for your applications - Michele Orselli- Codemotion A...
Collaborative Filtering 1: User-based CF
Introduction to recommender systems
Item based approach
PPT by Jannach_organized.pdf presentation on the recommendation
Recommender Systems and Linked Open Data
Introduction to Recommendation System
Lecture Notes on Recommender System Introduction
Recommendation Systems Roadtrip
Digital Trails Dave King 1 5 10 Part 2 D3
Overview of recommender system
Recsys 2016
Recommenders Systems
Recommended System.pptx
Recommendation Systems
Introduction to Recommendation Systems (Vietnam Web Submit)

More from Michele Orselli (20)

PDF
Tackling Tech Debt with Rector
PDF
Comunicare, condividere e mantenere decisioni architetturali nei team di svil...
PDF
A dive into Symfony 4
PDF
Hopping in clouds: a tale of migration from one cloud provider to another
PDF
Vagrant for real (codemotion rome 2016)
PDF
Vagrant for real codemotion (moar tips! ;-))
PDF
Migrare a Symfony 3
PDF
Vagrant for real
PDF
Implementing data sync apis for mibile apps @cloudconf
PDF
Server side data sync for mobile apps with silex
PDF
Continuous, continuous, continuous
PDF
Deploy a PHP App on Google App Engine
PDF
Implementing Server Side Data Synchronization for Mobile Apps
PDF
Deploy a php app on Google App Engine
PDF
PDF
Manage a project portfolio
PDF
Developing sustainable php projects
PDF
Zend Framework 2 per chi viene da Symfony2
PDF
BDD - Buzzword Driven Development - Build the next cool app for fun and for.....
KEY
Symfony CMF: un nuovo paradigma per la gestione dei contenuti
Tackling Tech Debt with Rector
Comunicare, condividere e mantenere decisioni architetturali nei team di svil...
A dive into Symfony 4
Hopping in clouds: a tale of migration from one cloud provider to another
Vagrant for real (codemotion rome 2016)
Vagrant for real codemotion (moar tips! ;-))
Migrare a Symfony 3
Vagrant for real
Implementing data sync apis for mibile apps @cloudconf
Server side data sync for mobile apps with silex
Continuous, continuous, continuous
Deploy a PHP App on Google App Engine
Implementing Server Side Data Synchronization for Mobile Apps
Deploy a php app on Google App Engine
Manage a project portfolio
Developing sustainable php projects
Zend Framework 2 per chi viene da Symfony2
BDD - Buzzword Driven Development - Build the next cool app for fun and for.....
Symfony CMF: un nuovo paradigma per la gestione dei contenuti

Recently uploaded (20)

PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
ai tools demonstartion for schools and inter college
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PPTX
L1 - Introduction to python Backend.pptx
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Nekopoi APK 2025 free lastest update
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
Online Work Permit System for Fast Permit Processing
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
top salesforce developer skills in 2025.pdf
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Digital Strategies for Manufacturing Companies
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
ai tools demonstartion for schools and inter college
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
L1 - Introduction to python Backend.pptx
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Nekopoi APK 2025 free lastest update
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Online Work Permit System for Fast Permit Processing
PTS Company Brochure 2025 (1).pdf.......
Understanding Forklifts - TECH EHS Solution
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Which alternative to Crystal Reports is best for small or large businesses.pdf
top salesforce developer skills in 2025.pdf
2025 Textile ERP Trends: SAP, Odoo & Oracle
How Creative Agencies Leverage Project Management Software.pdf
Digital Strategies for Manufacturing Companies
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool

A recommendation engine for your php application