Transcript
Page 1: You Might Also Like: Implementing User Recommendations in Rails

You  May  Also  Be  Interested  In:Implemen'ng  User  Recommenda'ons  in  Rails

Ma#hew  Deiterstheagiledeveloper.com

Thursday, June 10, 2010

Page 2: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

Thursday, June 10, 2010

Page 3: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

Thursday, June 10, 2010

Page 4: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

How  do  they  do  that?

Thursday, June 10, 2010

Page 5: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

think  about  our  data  in  new  ways

Thursday, June 10, 2010

Page 6: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

Understand  the  tools  to  do  something  interesBng

Thursday, June 10, 2010

Page 7: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

Use  those  tools  in  your  Rails  applicaBon

Thursday, June 10, 2010

Page 8: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

"Everything  should  be  made  as  simple  as  possible,  but  not  simpler."  

-­‐  Albert  Einstein

Thursday, June 10, 2010

Page 9: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

Thursday, June 10, 2010

Page 10: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

CreaBve  RevoluBonthe  Golden  Age  of  Adver;sing

Thursday, June 10, 2010

Page 11: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

Their  vision  of  consuming  life  had  liIle  to  do  with  actual  experience  of  American  consumers

Thursday, June 10, 2010

Page 12: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

An  Academic  approach

“Adver;sers  followed  the  wishes  of  conserva;ve  corporate  clients,  who  wanted  the  safe,  “scien;fc”  adver;sing

Thursday, June 10, 2010

Page 13: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

Technology  Changed&

Approach  Changed

Thursday, June 10, 2010

Page 14: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

In  the  late  40’s,  only  .05%  of  Americans  had  a  TV

End  of  50’s,  sBll  only  about  50%

5  years  later  in  1962,  90%  of  Americans  had  a  TV

Thursday, June 10, 2010

Page 15: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

Adver;sing  was  comfortable  “Male  dominated”  “academic”  approach

Audience  SegmentaBon

Thursday, June 10, 2010

Page 16: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

SimilariBes  in  Web  Development  Today

Thursday, June 10, 2010

Page 17: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

NoSQLDynamic  Languages

Thursday, June 10, 2010

Page 18: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

We’ve  been  doing  CRUD  for  30  yearsboring  for  us  and  the  user

Thursday, June 10, 2010

Page 19: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

Our  CreaBve  RevoluBonHow  can  we  change  our  approach

Thursday, June 10, 2010

Page 20: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

Amazon  is  reportedly  making  ~25%  of  sales  on  personalized  suggesBons

Net  sales  are  at  $7.13  billion  in  the  first  quarter  Jan-­‐Mar  2010  -­‐  roughly  2  billion  in  3  months

75%

25%

RecommendaBons  =  Money

Thursday, June 10, 2010

Page 21: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

#1  &  #2  –  StumbleUpon's  rank  among  social  media  traffic  sources  in  the  US.

118%  -­‐  the  growth  in  acBve  users  since  2009.

Almost  10  Million  registered  users

400  –  average  number  of  Bmes  a  user  stumbles  per  month.

RecommendaBons  =  Traffic

Thursday, June 10, 2010

Page 22: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

Discovering  the  relaBonships  in  your  data

Modeling  the  relaBonships

Using  graphs  in  your  Rails  App

Thursday, June 10, 2010

Page 23: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

Precious

Dick Cheney

President Obama ”The greatest thing about Facebook, is that you can quote something and totally make up the source.” - George Washington

John Adams lol...so true

Thursday, June 10, 2010

Page 24: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

Precious

Dick Cheney

President Obama ”The greatest thing about Facebook, is that you can quote something and totally make up the source.” - George Washington

John Adams lol...so true

Thursday, June 10, 2010

Page 25: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

http://www.hackdiary.com/2010/02/10/algorithmic-recruitment-with-github/Thursday, June 10, 2010

Page 26: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

Social  Networking

Content

Website  AnalyBcs

PredicBve  Analysis

Thursday, June 10, 2010

Page 27: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

Discovering  the  relaBonships  in  your  data

Modeling  the  relaBonships

Using  graphs  in  your  Rails  App

Thursday, June 10, 2010

Page 28: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

RelaBonal  Databases  !=  worksSQL  is  set  based

Thursday, June 10, 2010

Page 29: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

Lady GagaKevin Bacon

Thursday, June 10, 2010

Page 30: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

Lady GagaKevin Bacon

Thursday, June 10, 2010

Page 31: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

Example:  Finding  2  degrees  away  for  a  user  in  SQL

-­‐  100  people  executes  in  0.01  sec

-­‐  1000  people  executes  in  0.1  sec  

-­‐  4000  people  executes  in  17.78  sec  

-­‐  60K  over  an  hour

Thursday, June 10, 2010

Page 32: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

SQL  Smell

Courtsey of http://techportal.ibuildings.com/2009/09/07/graphs-in-the-database-sql-meets-social-networks/

WITH RECURSIVE transitive_closure(a, b, distance, path_string) AS( SELECT a, b, 1 AS distance, a || '.' || b || '.' AS path_string, b AS direct_connection FROM edges2 WHERE a = 1 -- set the starting node

  UNION ALL

  SELECT tc.a, e.b, tc.distance + 1, tc.path_string || e.b || '.' AS path_string, tc.direct_connection FROM edges2 AS e JOIN transitive_closure AS tc ON e.a = tc.b WHERE tc.path_string NOT LIKE '%' || e.b || '.%' AND tc.distance < 3)

SELECT * FROM transitive_closure--WHERE b=3 -- set the target node

ORDER BY a,b,distance

SELECT b FROM (

WITH RECURSIVE transitive_closure(a, b, distance, path_string) AS( SELECT a, b, 1 AS distance, a || '.' || b || '.' AS path_string FROM edges2 WHERE a = 1 -- set the starting node

  UNION ALL

  SELECT tc.a, e.b, tc.distance + 1, tc.path_string || e.b || '.' AS path_string FROM edges2 AS e JOIN transitive_closure AS tc ON e.a = tc.b WHERE tc.path_string NOT LIKE '%' || e.b || '.%' AND tc.distance = 0)

SELECT b FROM transitive_closureUNION ALL

(WITH RECURSIVE transitive_closure(a, b, distance, path_string) AS( SELECT a, b, 1 AS distance, a || '.' || b || '.' AS path_string FROM edges2 WHERE a = 4 -- set the target node

  UNION ALL

  SELECT tc.a, e.b, tc.distance + 1, tc.path_string || e.b || '.' AS path_string FROM edges2 AS e JOIN transitive_closure AS tc ON e.a = tc.b WHERE tc.path_string NOT LIKE '%' || e.b || '.%' AND tc.distance = 0)

SELECT b FROM transitive_closure)) AS immediate_connectionsGROUP BY b

HAVING COUNT(b) > 1;

2  degrees more  then  2  degrees

Thursday, June 10, 2010

Page 33: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

First Last

1

2

3

Luke Skywalker

Darth Vader

Princess Leah

How  is  Luke  connected  to  Princess  Leah?

Thursday, June 10, 2010

Page 34: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

First Last

1

2

3

Luke Skywalker

Darth Vader

Princess Leah

How  is  Luke  connected  to  Princess  Leah?

Thursday, June 10, 2010

Page 35: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

First Last

1

2

3

Luke Skywalker

Darth Vader

Princess Leah

How  is  Luke  connected  to  Princess  Leah?

Thursday, June 10, 2010

Page 36: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

First Last

1 Luke Skywalker

GraphsRela;onships  are  a  First  Class  Ci;zen  just  like  the  data

2 Darth Vader

3 Princess Leah

Father

Father

Thursday, June 10, 2010

Page 37: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

First Last

1 Luke Skywalker

Rows  Nodes

2 Darth Vader

3 Princess Leah

Father

Father

Node

Point

Actor

Vertex

Thursday, June 10, 2010

Page 38: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

First Last

1 Luke Skywalker

Edges

2 Darth Vader

3 Princess Leah

Father

Father

Edge

Rela;onship

Arc

Link

Thursday, June 10, 2010

Page 39: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

Less  complex,  100%  natural

Luke

PrincessDarth

Thursday, June 10, 2010

Page 40: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

Discovering  the  relaBonships  in  your  data

Modeling  the  relaBonships

Using  graphs  in  your  Rails  App

Thursday, June 10, 2010

Page 41: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

In  Memory  Ruby  GraphGreat  for  small  staBc  datasets  or  ad  hoc  querying

Thursday, June 10, 2010

Page 42: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

Rails App

RGL

RGL

Rails App

BackroundRB

RGL

or

Thursday, June 10, 2010

Page 43: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

# http://github.com/fmeyer/rgl

require 'rubygems'require 'rgl/adjacency'require 'rgl/dot'

graph = RGL::DirectedAdjacencyGraph.newgraph.add_edge 'mary', 'john'graph.add_edge 'mary', 'henery'graph.add_edge 'john', 'frank'graph.add_edge 'frank', 'henery'

# Use DOT to visualize this graph: # http://graphviz.org/Download_macos.phpgraph.write_to_graphic_file('jpg') `open graph.jpg`

Thursday, June 10, 2010

Page 44: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

20,000  nodes  and  1  million  edges  =  300  MB

Thursday, June 10, 2010

Page 45: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

Persistence  &  Dynamic  Data

Thursday, June 10, 2010

Page 46: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

Neo4j

Thursday, June 10, 2010

Page 47: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

Neo4j.rb

Neo4j

Rails App

Neo4j.rbLucene

Thursday, June 10, 2010

Page 48: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

class Person include Neo4j::NodeMixin property :name has_n :friendsend

Neo4j.startNeo4j::Transaction.run do andreas = Person.new :name => 'andreas' john = Person.new :name => 'John', :age => 30 andreas.friends << johnend

Thursday, June 10, 2010

Page 49: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

Neo4jr-­‐socialMore  REST,  Less  Java

Rails App

Neo4jr-social

Neo4j

Memcache

RDBMS

SolrLucene

Thursday, June 10, 2010

Page 50: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

Neo4jr-­‐socialThe  SOLR  of  Graphs  (uses  Neo4jr-­‐simple)

#> sudo gem install neo4jr-social

#> start-neo4jr-social

Thursday, June 10, 2010

Page 51: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

No  JRuby  Required

Packaged  as  self-­‐contained  jeIy  webserver

Deployable  WAR

Focused  on  SNA

Basic  Built  in  Querying

Extensible  ~/.neo4jr-­‐social

Thursday, June 10, 2010

Page 52: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

Facebook’s  Friend  SuggesBonsDemo

Johnathan

Thursday, June 10, 2010

Page 53: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

LinkedIn’s  Degrees  of  SeparaBonDemo

Johnathan

Thursday, June 10, 2010

Page 54: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

http://wiki.github.com/tinkerpop/gremlin/

Thursday, June 10, 2010

Page 55: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

SQLAssembly  Required

Graphs  (Neo4j)Works  out  of  the  Box

Thursday, June 10, 2010

Page 56: You Might Also Like: Implementing User Recommendations in Rails

AllSimplePaths  &  ShortestPath(Who  do  we  follow  on  Twiber  in  common)

Thursday, June 10, 2010

Page 57: You Might Also Like: Implementing User Recommendations in Rails

Thursday, June 10, 2010

Page 58: You Might Also Like: Implementing User Recommendations in Rails

AllSimplePaths  &  ShortestPath(Who  do  we  follow  on  Twiber  in  common)

Thursday, June 10, 2010

Page 59: You Might Also Like: Implementing User Recommendations in Rails

Dijkstra

score: 20 score: 5

score: 5

score: 5 score: 5

score: 5

score: 10

score: 10

(Who  do  we  follow  on  Twiber  in  common  -­‐  on  steroids)

Thursday, June 10, 2010

Page 60: You Might Also Like: Implementing User Recommendations in Rails

Closeness  Centrality(Who  has  the  most  followers  on  Twiber)

Thursday, June 10, 2010

Page 61: You Might Also Like: Implementing User Recommendations in Rails

Betweenness  Centrality

http://www.stoweboyd.com/message/its-betweenness-that-matters-not-your-eigenvalue-the-dark-ma.html

(Who  has  more  influen;al  people  following  them  on  Twiber)

Thursday, June 10, 2010

Page 62: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

http://www.hackdiary.com/2010/02/10/algorithmic-recruitment-with-github/Thursday, June 10, 2010

Page 63: You Might Also Like: Implementing User Recommendations in Rails

Eigenvector  Centrality(PageRank)

Thursday, June 10, 2010

Page 64: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

Performance

Thursday, June 10, 2010

Page 65: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

Sparse  vs  Dense

Thursday, June 10, 2010

Page 66: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

Thursday, June 10, 2010

Page 67: You Might Also Like: Implementing User Recommendations in Rails

Person

started_on => 'Jan 1 2010'finished_on => 'Jan 7 2010'hours => 40type => 'worked_on'

Project

Metadata

Thursday, June 10, 2010

Page 68: You Might Also Like: Implementing User Recommendations in Rails

Person

started_on => 1265639038finished_on => 1266243897hours => 40type => 'worked_on_reorg'

Project

Metadata

Thursday, June 10, 2010

Page 69: You Might Also Like: Implementing User Recommendations in Rails

Breadth or Depth

Thursday, June 10, 2010

Page 70: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

What  Next...

Thursday, June 10, 2010

Page 71: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

Inspired  to  think  about  your  data  in  new  ways

Thursday, June 10, 2010

Page 72: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

GraphsUnderstand  the  tools  to  do  something  

interes;ng  with  it

Thursday, June 10, 2010

Page 73: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

Use  these  tools  in  your  Rails  applicaBon

Thursday, June 10, 2010

Page 74: You Might Also Like: Implementing User Recommendations in Rails

NoSQL    AugmentaBon

Application

Memcache

RDBMS

Neo4j

Solr

Lucene

Thursday, June 10, 2010

Page 75: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

CreaBve  RevoluBon

Thursday, June 10, 2010

Page 76: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

QuesBons?

Thursday, June 10, 2010

Page 77: You Might Also Like: Implementing User Recommendations in Rails

theagiledeveloper.com                                                                                                                                                                                                                          @mdeiters

Links

•h#p://gist.github.com/431000

•h#p://github.com/andreasronge/neo4j

•h#p://github.com/mdeiters/neo4jr-­‐simple

•h#p://github.com/mdeiters/neo4jr-­‐social

•h#p://www.hackdiary.com/2010/02/10/algorithmic-­‐recruitment-­‐with-­‐github/

•h#p://techportal.ibuildings.com/2009/09/07/graphs-­‐in-­‐the-­‐database-­‐sql-­‐meets-­‐social-­‐networks/

Thursday, June 10, 2010


Top Related