# PageRank returns no difference in Recipe graph

**URL:** <https://community.neo4j.com/t/pagerank-returns-no-difference-in-recipe-graph/30440>\
**Category:** Graph Academy\
**Created:** [December 15, 2020, 3:30am UTC](https://community.neo4j.com/t/pagerank-returns-no-difference-in-recipe-graph/30440 "2020-12-15T03:30:43Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dongho](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/dongho/32/3279_2.png) [@Dongho](https://community.neo4j.com/u/Dongho)\
**Post date:** [December 15, 2020, 3:30am UTC](https://community.neo4j.com/t/pagerank-returns-no-difference-in-recipe-graph/30440/1 "2020-12-15T03:30:43Z")

</div>

I tried PageRank on this guide:  
[https://guides.neo4j.com/4.0-intro-graph-algos-exercises/PracticalApplication.html](https://guides.neo4j.com/4.0-intro-graph-algos-exercises/PracticalApplication.html)

I listed the score of PG for the largest group of Ingredient node then I only got the same score about 0.15 for all nodes:  
CALL gds.pageRank.stream({  
nodeQuery:'MATCH (i:Ingredient) WHERE i.ingredient\_community = 377  
RETURN id(i) as id',  
relationshipQuery:'MATCH (s:Ingredient)-[r:COMMONLY\_USED\_TOGETHER]-\>(t:Ingredient)  
WHERE s.ingredient\_community = 377 AND t.ingredient\_community = 377  
RETURN id(s) as source, id(t) as target,r.score as weight',  
relationshipWeightProperty:'weight'})  
YIELD nodeId,score  
return nodeId, score  
ORDER BY score DESC

How can I get more useful PG scores from this graph?

---

<div class="post-metadata">

**Author:** ![bratanic\_tomaz](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/bratanic_tomaz/32/26823_2.png) [@bratanic\_tomaz](https://community.neo4j.com/u/bratanic_tomaz)\
**Post date:** [December 15, 2020, 2:23pm UTC](https://community.neo4j.com/t/pagerank-returns-no-difference-in-recipe-graph/30440/2 "2020-12-15T14:23:14Z")

</div>

Hey gigauser,

When you get the same score of 0.15 for all nodes, that means that no relationships have been projected. The PageRank value of 0.15 is the default value for nodes with no incoming relationships.

Do you get any result when you run the following query:

```auto
MATCH p=(s:Ingredient)-[r:COMMONLY_USED_TOGETHER]->(t:Ingredient)
RETURN p LIMIT 10

```

If not, you should repeat Part 1, Part 3, and Part 5 of the guide.

---

<div class="post-metadata">

**Author:** ![Dongho](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/dongho/32/3279_2.png) [@Dongho](https://community.neo4j.com/u/Dongho)\
**Post date:** [December 15, 2020, 3:05pm UTC](https://community.neo4j.com/t/pagerank-returns-no-difference-in-recipe-graph/30440/3 "2020-12-15T15:05:22Z")

</div>

Hi Bratanic,

Thank you for the help. Yes I got the relationships. I wonder whether it is correct to have the relationships both directions.

 ![Screenshot from 2020-12-16 00-01-11](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/2X/5/53634f7e21aa714ee8fb3327ca7d8d5c02fdcff1.jpeg)

---

<div class="post-metadata">

**Author:** ![Dongho](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/dongho/32/3279_2.png) [@Dongho](https://community.neo4j.com/u/Dongho)\
**Post date:** [December 15, 2020, 3:16pm UTC](https://community.neo4j.com/t/pagerank-returns-no-difference-in-recipe-graph/30440/4 "2020-12-15T15:16:34Z")

</div>

You can test by loading the dataset. This guide looks no problem outwardly.  
I can get all result as it described. But when I looked the inside of the result by listing PG scores, I found some wrong in my graph or in this guide.  
CREATE CONSTRAINT ON (r:Recipe) ASSERT r.name IS UNIQUE  
CREATE CONSTRAINT ON (i:Ingredient) ASSERT i.name IS UNIQUE  
USING PERIODIC COMMIT 1000  
LOAD CSV WITH HEADERS FROM "[https://github.com/neo4j-apps/neuler/raw/master/sample-data/recipes/recipes.csv](https://github.com/neo4j-apps/neuler/raw/master/sample-data/recipes/recipes.csv)" AS row  
MERGE (r:Recipe{name:row.recipe})  
WITH r,row.ingredients as ingredients  
UNWIND split(ingredients,',') as ingredient  
MERGE (i:Ingredient{name:ingredient})  
MERGE (r)-[:CONTAINS\_INGREDIENT]-\>(i)

---

<div class="post-metadata">

**Author:** ![bratanic\_tomaz](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/bratanic_tomaz/32/26823_2.png) [@bratanic\_tomaz](https://community.neo4j.com/u/bratanic_tomaz)\
**Post date:** [December 15, 2020, 3:53pm UTC](https://community.neo4j.com/t/pagerank-returns-no-difference-in-recipe-graph/30440/5 "2020-12-15T15:53:57Z")

</div>

I have checked the dataset and found the error:

It seems that the query in part 3 should be fixed to:

`CALL gds.graph.writeRelationship('ingredient', 'COMMONLY_USED_TOGETHER', 'score')`

In the current setup, all relationship weights are null, because we don't export relationship properties from mutated relationships. Seems like when the relationship weights are null, PageRank algorithm dismisses the relationships as non-existent. I will report this to the GDS team. With the current setup, you would have to ignore relationship weights and it would work as well.

```auto
CALL gds.pageRank.stream({
nodeQuery:'MATCH (i:Ingredient) WHERE i.ingredient_community = 377
RETURN id(i) as id',
relationshipQuery:'MATCH (s:Ingredient)-[r:COMMONLY_USED_TOGETHER]->(t:Ingredient)
WHERE s.ingredient_community = 377 AND t.ingredient_community = 377
RETURN id(s) as source, id(t) as target,r.score as weight'})
YIELD nodeId,score
return nodeId, score
ORDER BY score DESC

```

Thanks for letting us know!

---

<div class="post-metadata">

**Author:** ![Dongho](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/dongho/32/3279_2.png) [@Dongho](https://community.neo4j.com/u/Dongho)\
**Post date:** [December 15, 2020, 4:12pm UTC](https://community.neo4j.com/t/pagerank-returns-no-difference-in-recipe-graph/30440/6 "2020-12-15T16:12:55Z")

</div>

What a nice of you! Now I can get the different PG scores from the graph.

Thank you for helping me teach my customers better with this guide.

Dongho.

---

<div class="post-metadata">

**Author:** ![vincentyuan1218](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/vincentyuan1218/32/22503_2.png) [@vincentyuan1218](https://community.neo4j.com/u/vincentyuan1218)\
**Post date:** [March 1, 2022, 12:40pm UTC](https://community.neo4j.com/t/pagerank-returns-no-difference-in-recipe-graph/30440/7 "2022-03-01T12:40:05Z")

</div>

Hi @bratanic_tomaz , did you get a chance to have it fixed? As right now I am running a fraud detection graph without weights in the relations and the pagerank scores are still all 0.15. I checked and the connection between nodes are there so wonder if it has something to do with the bug you mentioned?

---

<div class="post-metadata">

**Author:** ![bratanic\_tomaz](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/bratanic_tomaz/32/26823_2.png) [@bratanic\_tomaz](https://community.neo4j.com/u/bratanic_tomaz)\
**Post date:** [March 1, 2022, 12:57pm UTC](https://community.neo4j.com/t/pagerank-returns-no-difference-in-recipe-graph/30440/8 "2022-03-01T12:57:12Z")

</div>

I believe it's the same, if relationship weights are missing, then the relationship is dismissed. However, you can always use a default relationship weight property using either native or cypher projection.
