@@ -11,7 +11,7 @@ This Jupyter notebook is hosted
11
11
https://github.com/neo4j/graph-data-science-client/blob/main/examples/fastrp-and-knn.ipynb[here]
12
12
in the Neo4j Graph Data Science Client Github repository.
13
13
14
- The notebook exemplifies how to use the `+ graphdatascience+ ` Python
14
+ The notebook exemplifies how to use the `graphdatascience` Python
15
15
library to operate Neo4j GDS. It shows an adapted version of the FastRP
16
16
and kNN end-to-end example from the GDS Manual, found
17
17
https://neo4j.com/docs/graph-data-science/current/end-to-end-examples/fastrp-knn-example[here].
@@ -33,11 +33,11 @@ one of the customers will be recommended to the other.
33
33
== Prerequisites
34
34
35
35
Running this notebook requires a Neo4j server with a recent version
36
- (2.0+ ) of GDS installed. We recommend using Neo4j Desktop with GDS, or
37
- AuraDS.
36
+ (2.0{plus} ) of GDS installed. We recommend using Neo4j Desktop with GDS,
37
+ or AuraDS.
38
38
39
- The `+ graphdatascience+ ` Python library needs to be installed as well.
40
- See the examples in the Setup section below and in the
39
+ The `graphdatascience` Python library needs to be installed as well. See
40
+ the examples in the Setup section below and in the
41
41
https://neo4j.com/docs/graph-data-science-client/current/installation/[client
42
42
installation instructions].
43
43
@@ -80,7 +80,7 @@ assert gds.server_version() >= ServerVersion(1, 8, 0)
80
80
== Example graph creation
81
81
82
82
We now create a graph of products and customers in the database. The
83
- `+ amount+ ` relationship property represents the average weekly amount of
83
+ `amount` relationship property represents the average weekly amount of
84
84
money spent by a customer on a given product.
85
85
86
86
[source, python, role=no-test]
@@ -165,10 +165,10 @@ print(f"Graph '{G.name()}' node labels: {G.node_labels()}")
165
165
Next we use the
166
166
https://neo4j.com/docs/graph-data-science/current/machine-learning/node-embeddings/fastrp/[FastRP
167
167
algorithm] to generate node embeddings that capture topological
168
- information from the graph. We choose to work with
169
- `+embeddingDimension+` set to 4 which is sufficient since our example
170
- graph is very small. The `+ iterationWeights+ ` are chosen empirically to
171
- yield sensible results. Please see
168
+ information from the graph. We choose to work with `embeddingDimension`
169
+ set to 4 which is sufficient since our example graph is very small. The
170
+ ` iterationWeights` are chosen empirically to yield sensible results.
171
+ Please see
172
172
https://neo4j.com/docs/graph-data-science/current/machine-learning/node-embeddings/fastrp/#algorithms-embeddings-fastrp-syntax[the
173
173
syntax section of the FastRP documentation] for more information on
174
174
these parameters.
@@ -212,11 +212,11 @@ print(f"Number of embedding vectors produced: {result['nodePropertiesWritten']}"
212
212
Now we can run
213
213
https://neo4j.com/docs/graph-data-science/current/algorithms/knn/[kNN]
214
214
to identify similar nodes by using the node embeddings that we generated
215
- with FastRP as `+ nodeProperties+ `. Since we are working with a small
216
- graph, we can set `+ sampleRate+ ` to 1 and `+ deltaThreshold+ ` to 0
217
- without having to worry about long computation times. The
218
- `+concurrency+` parameter is set to 1 (along with the fixed
219
- `+randomSeed+`) in order to get a deterministic result. Please see
215
+ with FastRP as `nodeProperties`. Since we are working with a small
216
+ graph, we can set `sampleRate` to 1 and `deltaThreshold` to 0 without
217
+ having to worry about long computation times. The `concurrency`
218
+ parameter is set to 1 (along with the fixed `randomSeed`) in order to
219
+ get a deterministic result. Please see
220
220
https://neo4j.com/docs/graph-data-science/current/algorithms/knn/#algorithms-knn-syntax[the
221
221
syntax section of the kNN documentation] for more information on these
222
222
parameters.
@@ -252,10 +252,10 @@ paths between nodes leading to many similar FastRP node embeddings.
252
252
== Exploring the results
253
253
254
254
Let us now inspect the results of our kNN call by using Cypher. We can
255
- use the `+ SIMILARITY+ ` relationship type to filter out the relationships
255
+ use the `SIMILARITY` relationship type to filter out the relationships
256
256
we are interested in. And since we just care about similarities between
257
257
people for our product recommendation engine, we make sure to only match
258
- nodes with the `+ Person+ ` label.
258
+ nodes with the `Person` label.
259
259
260
260
Please see https://neo4j.com/docs/cypher-manual/current/[the Cypher
261
261
manual] for documentation on how to use Cypher.
@@ -271,23 +271,23 @@ gds.run_cypher(
271
271
)
272
272
----
273
273
274
- Our kNN results indicate among other things that the `+ Person+ ` nodes
275
- named "`Annie`" and "`Matt`" are very similar. Looking at the `+ BUYS+ `
274
+ Our kNN results indicate among other things that the `Person` nodes
275
+ named "`Annie`" and "`Matt`" are very similar. Looking at the `BUYS`
276
276
relationships for these two nodes we can see that such a conclusion
277
277
makes sense. They both buy three products, two of which are the same
278
- (`+ Product+ ` nodes named "`Cucumber`" and "`Tomatoes`") for both people
278
+ (`Product` nodes named "`Cucumber`" and "`Tomatoes`") for both people
279
279
and with similar amounts. We can therefore have high confidence in our
280
280
approach.
281
281
282
282
== Making recommendations
283
283
284
- Using the information we derived that the `+ Person+ ` nodes named
285
- "`Annie`" and "`Matt`" are similar, we can make product recommendations
286
- for each of them. Since they are similar, we can assume that products
287
- purchased by only one of the people may be of interest to buy also for
288
- the other person not already buying the product. By this principle we
289
- can derive product recommendations for the `+ Person+ ` named "`Matt`"
290
- using a simple Cypher query.
284
+ Using the information we derived that the `Person` nodes named "`Annie`"
285
+ and "`Matt`" are similar, we can make product recommendations for each
286
+ of them. Since they are similar, we can assume that products purchased
287
+ by only one of the people may be of interest to buy also for the other
288
+ person not already buying the product. By this principle we can derive
289
+ product recommendations for the `Person` named "`Matt`" using a simple
290
+ Cypher query.
291
291
292
292
[source, python, role=no-test]
293
293
----
@@ -326,5 +326,5 @@ derive some sensible product recommendations for a customer in our small
326
326
example.
327
327
328
328
To make sure to get similarities to other customers for every customer
329
- in our graph with kNN, we could play around with increasing the `+ topK+ `
329
+ in our graph with kNN, we could play around with increasing the `topK`
330
330
parameter.
0 commit comments