SlideShare ist ein Scribd-Unternehmen logo
1 von 90
Downloaden Sie, um offline zu lesen
Build a Recommendation
Engine with Neo4j and Python
‣ Download Neo4j: neo4j.com/download
‣ Open your browser to http://localhost:7474
‣ Type the following command:
:play http://guides.neo4j.com/pydatachi
Getting Started
Problem
Generic recommendations are
low efficacy…
Generic recommendations are
typically low efficacy…
Kevin Van Gundy | Building a Recommendation Engine with Neo4j and Python
Proposed Solution
"It's all about
relationships
- Kevin Van Gundy
-Lebron James"
…Data Relationships
CAR
DRIVES
name:	“Dan”	
born:	May	29,	1970	
twitter:	“@dan”
name:	“Ann”	
born:		Dec	5,	1975
since:	

Jan	10,	2011
brand:	“Volvo”	
model:	“V70”
Property Graph Model Components
Nodes
• The objects in the graph
• Can have name-value
properties
• Can be labeled
Relationships
• Relate nodes by type and
direction
• Can have name-value
properties
LOVES
LIKES
LIVES	WITH
OW
NS
PERSON PERSON
CAR
DRIVES
name:	“Dan”	
born:	May	29,	1970	
twitter:	“@dan”
name:	“Ann”	
born:		Dec	5,	1975
since:	

Jan	10,	2011
brand:	“Volvo”	
model:	“V70”
LOVES
LIKES
LIVES	WITH
OW
NS
PERSON PERSON
Storage on Disk
Introducing our data set...
meetup.com’s recommendations
Recommendation queries
‣ Several different types
• groups to join
• topics to follow
• events to attend
‣ As a user of meetup.com trying to find groups
to join and events to attend
The data
meetup.com/meetup_api/
Kevin Van Gundy | Building a Recommendation Engine with Neo4j and Python
Kevin Van Gundy | Building a Recommendation Engine with Neo4j and Python
What data do we have?
‣ Groups
‣ Members
‣ Events
‣ Topics
‣ Time & Date
‣ Location
Find similar groups to Neo4j
"As a member of the Outdoorsy Entrepreneur Meetup
I want to find other similar meetup groups
So that I can join those groups"
What makes groups similar?
‣ Download Neo4j: Neo4j.com/download
‣ Open your browser to http://localhost:7474
‣ Type the following command:
:play http://guides.neo4j.com/pydatachi
Recommend groups by topic
To the Browser!
Great Graphs
Batman!
Take Note
Indexes and Constraints
Unique constraints
We create unique constraints to:
‣ ensure uniqueness
‣ allow fast lookup of nodes which match these
(label,property) pairs.
CREATE	CONSTRAINT	ON	(t:Topic)	

ASSERT	t.id	IS	UNIQUE
Indexes
We create indexes to:
‣ Allow fast lookup of nodes which match these
(label,property) pairs.


CREATE	INDEX	ON	:Group(name)
The following are index backed:
‣ Equality
‣ STARTS WITH
‣ CONTAINS,
‣ ENDS WITH
‣ Range Searches
‣ (Non) Existence Checks
Indexes
How does Neo4j use indexes?
Indexes are only used to find the starting point for
queries.
Use index scans to look up
rows in tables and join them
with rows from other tables
Use indexes to find the starting
points for a query.
Relational
Graph
Next Guide
Group Membership
Watch Out
Transactions & WITH
Periodic Commit
Cypher keeps all transaction state in memory while
running a query which is fine most of the time.
Periodic Commit
Cypher keeps all transaction state in memory while
running a query which is fine most of the time…


But when using LOAD CSV, this state can get very
large and may result in an OutOfMemory exception.
Periodic Commit
// defaults to 1000

USING PERIODIC COMMIT
LOAD CSV 

...
Periodic Commit
// defaults to 1000

USING PERIODIC COMMIT 10000
LOAD CSV 

...
WITH
The WITH clause allows query parts to be chained
together, piping the results from one to be used as
starting points or criteria in the next.
WITH
It’s used to:
‣ Limit the number of entries that are then passed
on to other MATCH clauses
‣ Filter on aggregated values
‣ Separate reading from updating of the graph
Continue
Continue with the Guide
Exercise
Find yourself and your groups
Solution
Find yourself and your groups
Explore the graph
Type the following command into the Neo4j
browser to see the answers:
:play	http://guides.neo4j.com/reco/02_find_yourself_answers.html
Continue
Continue with the Guide
Find my similar groups
As a member of several meetup groups
I want to find other similar meetup groups
that I’m not already a member of
So that I can join those groups
Next Step
Member Interest
Member interests
Attention
Lists with split & UNWIND
Splitting up topic ids
The split function lets us convert a string into
a string array based on a delimiting character.

Splitting up topic ids
The split function lets us convert a string into a string
array based on a delimiting character.
RETURN split("1;2;3", ";") AS topicIds

[1, 2, 3]

We can use UNWIND to explode any array or list back
into individual rows.
Splitting up topic ids
We can use UNWIND to explode the resulting array back into individual rows.
UNWIND	[1,2,3]	AS	value	
RETURN	value

1	
2	
3
Splitting up topic ids
UNWIND split("1;2;3", ";") AS topicId
RETURN topicId
1
2
3
Splitting up topic ids
Continue
Continue with the Guide
Exercise
My inferred interests
Solution
My inferred interests
My inferred interests
Type the following command into the Neo4j
browser to see the answers:
:play	http://guides.neo4j.com/reco/03_inferred_answers.html
Continue
Continue with the Guide
Next Guide
Events
Exercise
Event recommendations
Solution
Event recommendations
Event recommendations
Type the following command into the Neo4j
browser to see the answers:
:play	http://guides.neo4j.com/reco/04_events_answers.html
Continue
Continue with the Guide
Next Guide
Venues
Exercise
Import venues
Solution
Import venues
Import venues
Type the following command into the Neo4j
browser to see the answers:
:play	http://guides.neo4j.com/reco/05_venues_import_answers.html
Continue
Continue with the Guide
Next Step
Calculating Distances
Continue
Continue with the Guide
Exercise
Using venues in recommendation
Solution
Using venues in recommendation
Using venues in recommendations
Type the following command into the Neo4j
browser to see the answers:
:play	http://guides.neo4j.com/reco/05_venues_distance_queries_answers.html
Using venues in recommendations
WITH	{latitude:	51.518551,	longitude:	-0.086114}	AS	here



MATCH	(member:Member	{name:	"Mark	Needham"})

							-[:MEMBER_OF]->()-[:HOSTED_EVENT]->(futureEvent),	
						(venue)<-[:VENUE]-(futureEvent)	
WHERE	futureEvent.time	>	timestamp()	
RETURN	group.name,	
							futureEvent.name,	
							round((futureEvent.time	-	timestamp())	/	(24.0*60*60*1000))	AS	days,	
							distance(venue,	here)	AS	distance	
ORDER	BY	days,	distance
Venues close to here
WITH	{latitude:	51.518551,	longitude:	-0.086114}	AS	here



MATCH	(member:Member	{name:	"Mark	Needham"})

							-[:MEMBER_OF]->()-[:HOSTED_EVENT]->(futureEvent),	
						(venue)<-[:VENUE]-(futureEvent)

WHERE	futureEvent.time	>	timestamp()	
WITH	group,	futureEvent,	distance(venue,	here)	AS	distance	
WHERE	distance	<	1000	
RETURN	group.name,	
							futureEvent.name,	
							round((futureEvent.time	-	timestamp())	/	(24.0*60*60*1000))	AS	days,	
							distance	
ORDER	BY	days,	distance

Next Guide
RSVPs
Exercise
Events at my venues
Solution
Events at my venues
Events at my venues
Type the following command into the Neo4j
browser to see the answers:
:play	http://guides.neo4j.com/reco/06_my_venues_answers.html
Next Guide
Procedures
Exercise
Import photos metadata
Solution
Import photos metadata
Import photos metadata
Type the following command into the Neo4j
browser to see the answers:
:play	http://guides.neo4j.com/reco/07_photos_answers.html
Next Guide
Latent Social Graph
Watch Out
Transaction State
Transaction State
Cypher keeps all transaction state in memory
while running a query which is fine most of the
time.


But when refactoring the graph, this state can get
very large and may result in an OutOfMemory
exception.
We therefore need to take a batched approach to
large scale refactorings.
MATCH	(m1:Process)	WITH	m1	LIMIT	1000
REMOVE	m1:Process
WITH	m1
//	do	the	refactoring
Batch all the things
Continue
Continue with the Guide
Exercise
Add friends to recommendation
Solution
Add friends to recommendation
Add friends to recommendation
Type the following command into the Neo4j
browser to see the answers:
:play	http://guides.neo4j.com/reco/08_latent_answers.html
Next Guide
Scoring
Next Guide
Your turn
JOIN NEO4J.COM/SLACK & #TRAINING-ATTENDEES

Weitere ähnliche Inhalte

Mehr von PyData

Mehr von PyData (20)

RESTful Machine Learning with Flask and TensorFlow Serving - Carlo Mazzaferro
RESTful Machine Learning with Flask and TensorFlow Serving - Carlo MazzaferroRESTful Machine Learning with Flask and TensorFlow Serving - Carlo Mazzaferro
RESTful Machine Learning with Flask and TensorFlow Serving - Carlo Mazzaferro
 
Mining dockless bikeshare and dockless scootershare trip data - Stefanie Brod...
Mining dockless bikeshare and dockless scootershare trip data - Stefanie Brod...Mining dockless bikeshare and dockless scootershare trip data - Stefanie Brod...
Mining dockless bikeshare and dockless scootershare trip data - Stefanie Brod...
 
Avoiding Bad Database Surprises: Simulation and Scalability - Steven Lott
Avoiding Bad Database Surprises: Simulation and Scalability - Steven LottAvoiding Bad Database Surprises: Simulation and Scalability - Steven Lott
Avoiding Bad Database Surprises: Simulation and Scalability - Steven Lott
 
Words in Space - Rebecca Bilbro
Words in Space - Rebecca BilbroWords in Space - Rebecca Bilbro
Words in Space - Rebecca Bilbro
 
End-to-End Machine learning pipelines for Python driven organizations - Nick ...
End-to-End Machine learning pipelines for Python driven organizations - Nick ...End-to-End Machine learning pipelines for Python driven organizations - Nick ...
End-to-End Machine learning pipelines for Python driven organizations - Nick ...
 
Pydata beautiful soup - Monica Puerto
Pydata beautiful soup - Monica PuertoPydata beautiful soup - Monica Puerto
Pydata beautiful soup - Monica Puerto
 
1D Convolutional Neural Networks for Time Series Modeling - Nathan Janos, Jef...
1D Convolutional Neural Networks for Time Series Modeling - Nathan Janos, Jef...1D Convolutional Neural Networks for Time Series Modeling - Nathan Janos, Jef...
1D Convolutional Neural Networks for Time Series Modeling - Nathan Janos, Jef...
 
Extending Pandas with Custom Types - Will Ayd
Extending Pandas with Custom Types - Will AydExtending Pandas with Custom Types - Will Ayd
Extending Pandas with Custom Types - Will Ayd
 
Measuring Model Fairness - Stephen Hoover
Measuring Model Fairness - Stephen HooverMeasuring Model Fairness - Stephen Hoover
Measuring Model Fairness - Stephen Hoover
 
What's the Science in Data Science? - Skipper Seabold
What's the Science in Data Science? - Skipper SeaboldWhat's the Science in Data Science? - Skipper Seabold
What's the Science in Data Science? - Skipper Seabold
 
Applying Statistical Modeling and Machine Learning to Perform Time-Series For...
Applying Statistical Modeling and Machine Learning to Perform Time-Series For...Applying Statistical Modeling and Machine Learning to Perform Time-Series For...
Applying Statistical Modeling and Machine Learning to Perform Time-Series For...
 
Solving very simple substitution ciphers algorithmically - Stephen Enright-Ward
Solving very simple substitution ciphers algorithmically - Stephen Enright-WardSolving very simple substitution ciphers algorithmically - Stephen Enright-Ward
Solving very simple substitution ciphers algorithmically - Stephen Enright-Ward
 
The Face of Nanomaterials: Insightful Classification Using Deep Learning - An...
The Face of Nanomaterials: Insightful Classification Using Deep Learning - An...The Face of Nanomaterials: Insightful Classification Using Deep Learning - An...
The Face of Nanomaterials: Insightful Classification Using Deep Learning - An...
 
Deprecating the state machine: building conversational AI with the Rasa stack...
Deprecating the state machine: building conversational AI with the Rasa stack...Deprecating the state machine: building conversational AI with the Rasa stack...
Deprecating the state machine: building conversational AI with the Rasa stack...
 
Towards automating machine learning: benchmarking tools for hyperparameter tu...
Towards automating machine learning: benchmarking tools for hyperparameter tu...Towards automating machine learning: benchmarking tools for hyperparameter tu...
Towards automating machine learning: benchmarking tools for hyperparameter tu...
 
Using GANs to improve generalization in a semi-supervised setting - trying it...
Using GANs to improve generalization in a semi-supervised setting - trying it...Using GANs to improve generalization in a semi-supervised setting - trying it...
Using GANs to improve generalization in a semi-supervised setting - trying it...
 
LightFields.jl: Fast 3D image reconstruction for VR applications - Hector And...
LightFields.jl: Fast 3D image reconstruction for VR applications - Hector And...LightFields.jl: Fast 3D image reconstruction for VR applications - Hector And...
LightFields.jl: Fast 3D image reconstruction for VR applications - Hector And...
 
Extracting relevant Metrics with Spectral Clustering - Evelyn Trautmann
Extracting relevant Metrics with Spectral Clustering - Evelyn TrautmannExtracting relevant Metrics with Spectral Clustering - Evelyn Trautmann
Extracting relevant Metrics with Spectral Clustering - Evelyn Trautmann
 
GDPR in practise - Developing models with transparency and privacy in mind - ...
GDPR in practise - Developing models with transparency and privacy in mind - ...GDPR in practise - Developing models with transparency and privacy in mind - ...
GDPR in practise - Developing models with transparency and privacy in mind - ...
 
From cells to drug responses - machine learning in cancer research - Julian d...
From cells to drug responses - machine learning in cancer research - Julian d...From cells to drug responses - machine learning in cancer research - Julian d...
From cells to drug responses - machine learning in cancer research - Julian d...
 

Kürzlich hochgeladen

Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
nirzagarg
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
nirzagarg
 
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
nirzagarg
 
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Klinik kandungan
 
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
gajnagarg
 
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
Health
 

Kürzlich hochgeladen (20)

Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
Top profile Call Girls In Bihar Sharif [ 7014168258 ] Call Me For Genuine Mod...
 
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book nowVadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
Vadodara 💋 Call Girl 7737669865 Call Girls in Vadodara Escort service book now
 
Dubai Call Girls Peeing O525547819 Call Girls Dubai
Dubai Call Girls Peeing O525547819 Call Girls DubaiDubai Call Girls Peeing O525547819 Call Girls Dubai
Dubai Call Girls Peeing O525547819 Call Girls Dubai
 
Statistics notes ,it includes mean to index numbers
Statistics notes ,it includes mean to index numbersStatistics notes ,it includes mean to index numbers
Statistics notes ,it includes mean to index numbers
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Research
 
High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...
High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...
High Profile Call Girls Service in Jalore { 9332606886 } VVIP NISHA Call Girl...
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
Top profile Call Girls In Hapur [ 7014168258 ] Call Me For Genuine Models We ...
 
7. Epi of Chronic respiratory diseases.ppt
7. Epi of Chronic respiratory diseases.ppt7. Epi of Chronic respiratory diseases.ppt
7. Epi of Chronic respiratory diseases.ppt
 
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptxRESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
RESEARCH-FINAL-DEFENSE-PPT-TEMPLATE.pptx
 
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
SAC 25 Final National, Regional & Local Angel Group Investing Insights 2024 0...
 
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
Top profile Call Girls In Purnia [ 7014168258 ] Call Me For Genuine Models We...
 
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
Jual obat aborsi Bandung ( 085657271886 ) Cytote pil telat bulan penggugur ka...
 
Ranking and Scoring Exercises for Research
Ranking and Scoring Exercises for ResearchRanking and Scoring Exercises for Research
Ranking and Scoring Exercises for Research
 
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
 
20240412-SmartCityIndex-2024-Full-Report.pdf
20240412-SmartCityIndex-2024-Full-Report.pdf20240412-SmartCityIndex-2024-Full-Report.pdf
20240412-SmartCityIndex-2024-Full-Report.pdf
 
Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...
Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...
Gomti Nagar & best call girls in Lucknow | 9548273370 Independent Escorts & D...
 
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
Top profile Call Girls In Chandrapur [ 7014168258 ] Call Me For Genuine Model...
 
Fun all Day Call Girls in Jaipur 9332606886 High Profile Call Girls You Ca...
Fun all Day Call Girls in Jaipur   9332606886  High Profile Call Girls You Ca...Fun all Day Call Girls in Jaipur   9332606886  High Profile Call Girls You Ca...
Fun all Day Call Girls in Jaipur 9332606886 High Profile Call Girls You Ca...
 
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
+97470301568>>weed for sale in qatar ,weed for sale in dubai,weed for sale in...
 

Kevin Van Gundy | Building a Recommendation Engine with Neo4j and Python