Exploring Yelp Dataset with Neo4j — Part II: PageRank

CALL gds.graph.create(
'my-graph',
{
User: {
label: 'User'
}
},
{
FRIEND_OF: {
type: 'FRIENDS',
orientation: 'UNDIRECTED'
}
}
)
PageRank formula (Original)
PageRank formula (GDS’s Implementation)
  • dampingFactor: default 0.85.
  • tolerance: default 0.0000001.
  • maxIterations: default 20.
# Use anonymous projected graph so no need to clean up later.
UNWIND [20, 30, 40] AS numIter
CALL gds.pageRank.write({
nodeProjection: 'User',
relationshipProjection: {
FRIEND_OF: {
type: 'FRIENDS',
orientation: 'UNDIRECTED'
}
},
writeProperty: 'pageRank' + toString(numIter),
maxIterations: numIter
})
YIELD ranIterations, didConverge, createMillis, computeMillis, writeMillis, nodePropertiesWritten, centralityDistribution, configuration
RETURN numIter, ranIterations, didConverge, createMillis, computeMillis, writeMillis, nodePropertiesWritten, centralityDistribution, configuration
UNWIND ['Hotels', 'Hostels'] as cat_name
MATCH (c:Category {category_id: cat_name})<-[:IN_CATEGORY]-(:Business)<-[:REVIEWS]-(:Review)<-[:WROTE]-(u:User)
WITH c, u
WITH c.category_id AS category_id, apoc.coll.sortNodes(COLLECT(DISTINCT u), "pageRank20")[..10] AS userWithPageRank20, apoc.coll.sortNodes(COLLECT(DISTINCT u), "pageRank30")[..10] AS userWithPageRank30, apoc.coll.sortNodes(COLLECT(DISTINCT u), "pageRank40")[..10] AS userWithPageRank40, range(0, 9, 1) AS indexes
UNWIND indexes AS index
RETURN category_id, userWithPageRank20[index].name AS name20, userWithPageRank20[index].pageRank20 AS pageRank20, userWithPageRank30[index].name AS name30, userWithPageRank30[index].pageRank30 AS pageRank30, userWithPageRank40[index].name AS name40, userWithPageRank40[index].pageRank40 AS pageRank40
Top 10 PageRank scores for Category “Hotels” and “Hostels”

Appendix

# degree: the number of out-links for a given node.
var iter = graph.nodeIterator();
while(iter.hasNext()){
var node = iter.next();
var degree = graph.degree(node);
getProgressLogger().logMessage(String.format("*** node [%s]: has degree [%s]", node, degree));
}
CREATE (a:User {name: "a"}), (b:User {name: "b"}), (c:User {name: "c"}), (a)-[:FRIEND_WITH]->(b), (c)-[:FRIEND_WITH]->(b)
CALL gds.pageRank.write({
nodeProjection: 'User',
relationshipProjection: 'FRIEND_WITH',
writeProperty: 'pageRank',
maxIterations: 20
})
YIELD ranIterations, didConverge, createMillis, computeMillis, writeMillis, nodePropertiesWritten, centralityDistribution, configuration
*** node [0]: has degree [1]
*** node [1]: has degree [1]
*** node [2]: has degree [0]

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store