-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Centrality Algorithms Example Jupyter Notebook #386
Conversation
✅ Deploy Preview for neo4j-graph-data-science-client canceled.
|
Umm. I don't know why one check is not running :/ |
@kedarghule The check not running is normal. For security reasons we do not run PR builds from non-members. There have been several attacks made on our public repositories to attempt to expose secrets from our build system. I apologise for the delayed review. We are in the process of releasing GDS All the best |
Alright @Mats-SX and sure, no problem :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for this contribution! It's a great notebook. I only have a few comments.
I will push a commit that clears output cells and applies our code style rules to the Python code. For reference, we have two scripts in the scripts
directory: checkstyle
and makestyle
that can be used (just run them as scripts/checkstyle
without arguments) to manage this in future contributions.
I will also create a sibling PR to allow our CI to run.
"gds.run_cypher(\n", | ||
" \"UNWIND $nodes AS node CREATE (n:City {node_id: node.node_id, name: node.name, population: node.metro_pop})\",\n", | ||
" params={\"nodes\": nodes_info_df.to_dict(\"records\")},\n", | ||
")\n", | ||
"\n", | ||
"gds.run_cypher(\n", | ||
" \"\"\"\n", | ||
" UNWIND $rels AS rel \n", | ||
" MATCH (source:City {node_id: rel.Origin}), (target:City {node_id: rel.Destination}) \n", | ||
" CREATE (source)-[:HAS_FLIGHT_TO]->(target)\n", | ||
" \"\"\",\n", | ||
" params={\"rels\": routes_df.to_dict(\"records\")},\n", | ||
")" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method of importing data to the database is a good choice for a graph of this size (small).
examples/centrality-algorithms.ipynb
Outdated
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Next, we load this data (nodes and edges) into a Graph Database and a GDS graph." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relating to the comment on the next section, I think it would be good to add a small note here that for graphs of larger size (like, 100k to millions of nodes) other importing measures should be considered (batching, neo4j-admin import
or Arrow CREATE DATABASE
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could just have something like
Since this graph is very small, a straight-forward Cypher
UNWIND
query is the simplest way to create our graph in the database.
Larger graphs may need a more sophisticated importing technique.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright. Done :)
examples/centrality-algorithms.ipynb
Outdated
"# We can use convenience methods on `G` to check if the projection looks correct\n", | ||
"print(f\"Graph '{G.name()}' node count: {G.node_count()}\")\n", | ||
"print(f\"Graph '{G.name()}' node labels: {G.node_labels()}\")" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be nice to also print the relationshipCount
here, and maybe comment that the counts match the expected counts from the SNAP website
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
examples/centrality-algorithms.ipynb
Outdated
"if eigenvector_centrality_result.didConverge: \n", | ||
" print(f\"The number of iterations taken by Eigenvector Centrality to run is {eigenvector_centrality_result.ranIterations}.\")\n", | ||
"else:\n", | ||
" print(\"Algorithm did not converge!\")" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very elegant!
examples/centrality-algorithms.ipynb
Outdated
{ | ||
"data": { | ||
"text/plain": [ | ||
"{'p99': 0.08469437807798386,\n", | ||
" 'min': 0.0012630745768547058,\n", | ||
" 'max': 0.0856785699725151,\n", | ||
" 'mean': 0.041094380038741385,\n", | ||
" 'p90': 0.07575749605894089,\n", | ||
" 'p50': 0.0386042520403862,\n", | ||
" 'p999': 0.0856785699725151,\n", | ||
" 'p95': 0.08167456835508347,\n", | ||
" 'p75': 0.05822562426328659}" | ||
] | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better if we commit the notebook without cell outputs. Could you clear these and commit with empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I think you already did this for me. Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I noticed that our makestyle
script does this automatically :)
"source": [ | ||
"gds.graph.nodeProperties.write(G, [\"eigenvectorCentrality\"])" | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should have a small markdown cell before this one that tells the reader that we are about to write our results back to the database
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
"source": [ | ||
"gds.graph.nodeProperties.write(G, [\"betweennessCentrality\"])" | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's also add a small sentence about this operation
examples/centrality-algorithms.ipynb
Outdated
"source": [ | ||
"### References\n", | ||
"- For the network:\n", | ||
"Brendan J. Frey and Delbert Dueck. \"Clustering by passing messages between data points.\" Science 315.5814 (2007): 972-976.\n", | ||
"\n", | ||
"- For the city metadata (metropolitan population, latitude, and longitude):\n", | ||
"Austin R. Benson, David F. Gleich, and Jure Leskovec. \"Higher-order Organization of Complex Networks.\" Science, 353.6295 (2016): 163–166.\n", | ||
"\n", | ||
"- Notebook contributed by [Kedar Ghule](https://github.com/kedarghule)" | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good list! Maybe let's also add the link to the SNAP dataset page that we had in the introduction for completeness
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
2dc053c
to
2fdd333
Compare
2fdd333
to
5bbbb46
Compare
@Mats-SX I have addressed your comments for the PR and made a new commit. Please let me know if anything else is needed or if I missed anything. Also the latest commit won't run a check again :/ |
examples/centrality-algorithms.ipynb
Outdated
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"name": "python" | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.11" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This stuff was added back in, which is normal when the notebook is run. I will clear it out again.
@kedarghule Thank you! I've kicked off another CI build. |
This PR adds an example jupyter notebook for centrality algorithms on the airline travel reachability network dataset. The notebook explores eigenvector centrality, betweenness centrality & degree centrality.
This is in reference to my comment in the issue: #254
Thank you :)