# Graph projections

**URL:** <https://community.neo4j.com/t/graph-projections/59690>\
**Category:** Neo4j Graph Platform\
**Tags:** migrated\
**Created:** [July 19, 2022, 7:57am UTC](https://community.neo4j.com/t/graph-projections/59690 "2022-07-19T07:57:55Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![MeghanaS](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/meghanas/32/26231_2.png) [@MeghanaS](https://community.neo4j.com/u/MeghanaS)\
**Post date:** [July 19, 2022, 7:57am UTC](https://community.neo4j.com/t/graph-projections/59690/1 "2022-07-19T07:57:55Z")

</div>

Hi,

Kindly clarify the following:

1. Does projecting all the nodes and relationships of a graph also project their properties?

2. Is it not possible to use type properties as one of the features while training a graph algorithm?

3. I have a KG from an ecommerce website. I have user node, session node, orders node and their relationships etc. I am trying to use link prediction algorithm to predict the link between an order node and a recipient node. Is there any useful resource that I could refer?

I am a beginner in neo4j GDS. Any help is appreciated. Thanks in advance!

---

<div class="post-metadata">

**Author:** ![MeghanaS](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/meghanas/32/26231_2.png) [@MeghanaS](https://community.neo4j.com/u/MeghanaS)\
**Post date:** [July 19, 2022, 10:36am UTC](https://community.neo4j.com/t/graph-projections/59690/2 "2022-07-19T10:36:18Z")

</div>

Thanks [@Cobra](https://community.neo4j.com/t5/user/viewprofilepage/user-id/3843) for the reply,  
3. I went through the example actually and was able to understand quite a bit. The issue I am not able to relate it to my use case which is link pred. Main problem is how to split the graph for training and testing. i.e., I have a particular relationship and this relationship is missing between few nodes. I need my train set to have a graph with the relation and test set to be without the relation. So that the model is able to predict missing relations of the test graph. There are only a few uses which are very simple.

---

<div class="post-metadata">

**Author:** ![Cobra](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/cobra/32/35243_2.png) [@Cobra](https://community.neo4j.com/u/Cobra)\
**Post date:** [July 19, 2022, 8:07am UTC](https://community.neo4j.com/t/graph-projections/59690/3 "2022-07-19T08:07:44Z")

</div>

Hello [@MeghanaS](https://community.neo4j.com/t5/user/viewprofilepage/user-id/14794) 😊

1. No, you must specify the properties you want to project: [example](https://neo4j.com/docs/graph-data-science/current/graph-project/#node-properties-example).
2. No, but you can use [One-Hot Encoding](https://neo4j.com/docs/graph-data-science/current/alpha-algorithms/one-hot-encoding/) function to use string values in Machine Learning algorithms.
3. You can start with the [Product recommendation engine using FastRP and kNN](https://neo4j.com/docs/graph-data-science/current/end-to-end-examples/fastrp-knn-example/) example.

In addition, I advise you to do these free courses before starting:

1. [Introduction to Neo4j Graph Data Science](https://graphacademy.neo4j.com/courses/gds-product-introduction/)
2. [Neo4j Graph Data Science Fundamentals](https://graphacademy.neo4j.com/courses/graph-data-science-fundamentals/)

Regards,  
Cobra

---

<div class="post-metadata">

**Author:** ![Cobra](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/cobra/32/35243_2.png) [@Cobra](https://community.neo4j.com/u/Cobra)\
**Post date:** [July 19, 2022, 3:18pm UTC](https://community.neo4j.com/t/graph-projections/59690/4 "2022-07-19T15:18:56Z")

</div>

I think you have two options:

1. If you want to use [Link Prediction algorithms of GDS](https://neo4j.com/docs/graph-data-science/current/algorithms/linkprediction/), you don't need to split your graph into train/test/validation.
2. If you want to use Machine Learning, you should have a look [here](https://neo4j.com/docs/graph-data-science/current/machine-learning/linkprediction-pipelines/link-prediction/) where everything is explained.

Regards,  
Cobra

---

<div class="post-metadata">

**Author:** ![MeghanaS](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/meghanas/32/26231_2.png) [@MeghanaS](https://community.neo4j.com/u/MeghanaS)\
**Post date:** [July 19, 2022, 5:01pm UTC](https://community.neo4j.com/t/graph-projections/59690/5 "2022-07-19T17:01:27Z")

</div>

1. This makes sense. But here it is used only for a pair of similar nodes. My use case is to predict relation between nodes but of different type. Let me define my problem statement first.  
I have a graph something like this.  
(:session)-[:contains]-\>(:order), (:customer)-[:has]-\>(:session),(:order)-[:has]-\>(:product), (:order)-[:to]-\>(:relation)  
There are many customers who have placed orders. Some of the orders specify to whom the order was intended to (relation) i.e., mother/father etc. and some orders do not. For these orders my intention is to predict to whom the order was likely intended to. Any suggestions?

---

<div class="post-metadata">

**Author:** ![Cobra](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/cobra/32/35243_2.png) [@Cobra](https://community.neo4j.com/u/Cobra)\
**Post date:** [July 19, 2022, 8:58pm UTC](https://community.neo4j.com/t/graph-projections/59690/6 "2022-07-19T20:58:57Z")

</div>

I guess you can start without a machine learning pipeline, last time I worked with a recommendation engine I used Adamic Adar to recommend sessions of formation. Here are some articles if you need more explanation:

- [https://medium.com/@dishasuyogi/link-prediction-3bd1a9a79f29](https://medium.com/@dishasuyogi/link-prediction-3bd1a9a79f29)
- [https://medium.com/neo4j/link-prediction-with-neo4j-part-1-an-introduction-713aa779fd9](https://medium.com/neo4j/link-prediction-with-neo4j-part-1-an-introduction-713aa779fd9)
- [https://en.wikipedia.org/wiki/Adamic%E2%80%93Adar\_index](https://en.wikipedia.org/wiki/Adamic%E2%80%93Adar_index)
- [https://neo4j.com/docs/graph-data-science/current/alpha-algorithms/adamic-adar/](https://neo4j.com/docs/graph-data-science/current/alpha-algorithms/adamic-adar/)

You can compute the score between orders which will give you a score then create the relation between the order and the relation with the score in it. The issue with this method is that you will have the same score for everyone. For heterogeneous graph, I think you will have to use machine learning pipeline.

Regards,  
Cobra

---

<div class="post-metadata">

**Author:** ![MeghanaS](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/meghanas/32/26231_2.png) [@MeghanaS](https://community.neo4j.com/u/MeghanaS)\
**Post date:** [July 20, 2022, 12:23pm UTC](https://community.neo4j.com/t/graph-projections/59690/7 "2022-07-20T12:23:32Z")

</div>

I did an estimate before training, and the mem available is less than required.

---

<div class="post-metadata">

**Author:** ![MeghanaS](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/meghanas/32/26231_2.png) [@MeghanaS](https://community.neo4j.com/u/MeghanaS)\
**Post date:** [July 20, 2022, 6:41am UTC](https://community.neo4j.com/t/graph-projections/59690/8 "2022-07-20T06:41:11Z")

</div>

Yes correct. But again 2 issues here .

1. I want to the train set to have only positive samples i.e., graph containing the relation between order & relation. Test set to have only negative samples. i.e., graph not containing the relation between order & relation.  
The way we do in classic ML and DL. It should be able to learn from the train and predict them in test. But here I see both train and test will have negative samples.
2. I do not want the model to predict missing links between every other node rather it should be able to predict between only order node and relation node  
How do I achieve this?

---

<div class="post-metadata">

**Author:** ![Cobra](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/cobra/32/35243_2.png) [@Cobra](https://community.neo4j.com/u/Cobra)\
**Post date:** [July 20, 2022, 12:51pm UTC](https://community.neo4j.com/t/graph-projections/59690/9 "2022-07-20T12:51:36Z")

</div>

You need to increase the the power allocated to the database and you should [estimate](https://neo4j.com/docs/graph-data-science/current/common-usage/memory-estimation/) the procedure before starting it.

---

<div class="post-metadata">

**Author:** ![Cobra](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/cobra/32/35243_2.png) [@Cobra](https://community.neo4j.com/u/Cobra)\
**Post date:** [July 20, 2022, 7:57am UTC](https://community.neo4j.com/t/graph-projections/59690/10 "2022-07-20T07:57:25Z")

</div>

You should have a look at this [setting](https://neo4j.com/docs/graph-data-science/current/machine-learning/linkprediction-pipelines/theory/#linkprediction-pipelines-classimbalance).

---

<div class="post-metadata">

**Author:** ![MeghanaS](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/meghanas/32/26231_2.png) [@MeghanaS](https://community.neo4j.com/u/MeghanaS)\
**Post date:** [July 20, 2022, 1:23pm UTC](https://community.neo4j.com/t/graph-projections/59690/11 "2022-07-20T13:23:47Z")

</div>

I have deleted the unused nodes/relations in the projected graph. Lets see😊

---

<div class="post-metadata">

**Author:** ![MeghanaS](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/meghanas/32/26231_2.png) [@MeghanaS](https://community.neo4j.com/u/MeghanaS)\
**Post date:** [July 20, 2022, 5:36am UTC](https://community.neo4j.com/t/graph-projections/59690/12 "2022-07-20T05:36:26Z")

</div>

Yes. I have a heterogenous graph and need to use a pipeline.

---

<div class="post-metadata">

**Author:** ![Cobra](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/cobra/32/35243_2.png) [@Cobra](https://community.neo4j.com/u/Cobra)\
**Post date:** [July 20, 2022, 6:16am UTC](https://community.neo4j.com/t/graph-projections/59690/13 "2022-07-20T06:16:09Z")

</div>

Then, if you follow [this example](https://neo4j.com/docs/graph-data-science/current/machine-learning/linkprediction-pipelines/link-prediction/), it should help you solve your use case.

---

<div class="post-metadata">

**Author:** ![MeghanaS](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/meghanas/32/26231_2.png) [@MeghanaS](https://community.neo4j.com/u/MeghanaS)\
**Post date:** [July 22, 2022, 2:12pm UTC](https://community.neo4j.com/t/graph-projections/59690/14 "2022-07-22T14:12:24Z")

</div>

Okay.. Is it not possible to make the model predict only for specified nodes before hand?

Also,

Below is an example of exhaustive search prediction given in the doc. Here relationshipType means that the graph is filtered on KNOWS relation. There would be no disconnected nodes for prediction in such case am I right? Please correct me if I am wrong.  
CALL gds.beta.pipeline.linkPrediction.predict.mutate('myGraph',  
{ modelName: 'lp-pipeline-model',  
relationshipTypes: ['KNOWS'],  
mutateRelationshipType: 'KNOWS\_EXHAUSTIVE\_PREDICTED',  
topN: 5, threshold: 0.45 })YIELD relationshipsWritten, samplingStats

---

<div class="post-metadata">

**Author:** ![MeghanaS](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/meghanas/32/26231_2.png) [@MeghanaS](https://community.neo4j.com/u/MeghanaS)\
**Post date:** [July 22, 2022, 12:16pm UTC](https://community.neo4j.com/t/graph-projections/59690/15 "2022-07-22T12:16:44Z")

</div>

So, I was able to train the model and the model is now ready for predictions.  
There are 2 ways of prediction: Exhaustive search, Approximate search. The first one predicts for all unconnected nodes and the second one applies KNN to predict. I do not want both; rather I want the model to predict the link only between 2 specific nodes 'order' node and 'relation' node.. Is there any way to achieve this?

---

<div class="post-metadata">

**Author:** ![Cobra](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/cobra/32/35243_2.png) [@Cobra](https://community.neo4j.com/u/Cobra)\
**Post date:** [July 22, 2022, 3:23pm UTC](https://community.neo4j.com/t/graph-projections/59690/16 "2022-07-22T15:23:15Z")

</div>

I know [link prediction algorithms](https://neo4j.com/docs/graph-data-science/current/algorithms/linkprediction/) can predict between two nodes but I don't know for machine learning pipeline.

Yeah, according to the documentation: relationshipTypes means: Filter the named graph using the given relationship types.

Regards,  
Cobra

---

<div class="post-metadata">

**Author:** ![Cobra](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/cobra/32/35243_2.png) [@Cobra](https://community.neo4j.com/u/Cobra)\
**Post date:** [July 22, 2022, 1:58pm UTC](https://community.neo4j.com/t/graph-projections/59690/17 "2022-07-22T13:58:56Z")

</div>

With the stream method, you can add a WHERE clause after the YIELD to only return the score between the nodes you are interested in.

---

<div class="post-metadata">

**Author:** ![MeghanaS](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/meghanas/32/26231_2.png) [@MeghanaS](https://community.neo4j.com/u/MeghanaS)\
**Post date:** [July 25, 2022, 12:53pm UTC](https://community.neo4j.com/t/graph-projections/59690/18 "2022-07-25T12:53:14Z")

</div>

Hi again,  
How do I query the relationships from a projected graph? i.e., I have a few relationships predicted from my LP model and I want to see between how many nodes is this new relation created.

---

<div class="post-metadata">

**Author:** ![Cobra](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/cobra/32/35243_2.png) [@Cobra](https://community.neo4j.com/u/Cobra)\
**Post date:** [July 25, 2022, 1:14pm UTC](https://community.neo4j.com/t/graph-projections/59690/19 "2022-07-25T13:14:08Z")

</div>

You can use [this](https://neo4j.com/docs/graph-data-science/current/management-ops/create-cypher-db/) but it is in alpha tiers.

---

<div class="post-metadata">

**Author:** ![MeghanaS](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/meghanas/32/26231_2.png) [@MeghanaS](https://community.neo4j.com/u/MeghanaS)\
**Post date:** [August 2, 2022, 10:46am UTC](https://community.neo4j.com/t/graph-projections/59690/20 "2022-08-02T10:46:55Z")

</div>

Hi,  
I resumed the work today and am able to stream my predicted relationships and their probabilities also. Below is the code

CALL gds.graph.streamRelationshipProperty(

'mygraph',

'predictied\_probablity\_score',

['predicted\_relationship\_name']

)

YIELD

sourceNodeId, targetNodeId, relationshipType, propertyValue

RETURN

gds.util.asNode(sourceNodeId).name as source, gds.util.asNode(targetNodeId).name as target, relationshipType, propertyValue

ORDER BY source ASC, target ASC

The issue here is now, I am getting all the source and target nodes as NULL.

[Next page](https://community.neo4j.com/t/graph-projections/59690.md?page=2)
