Exécuter des algorithmes GDS
Apprenez à exécuter différents algorithmes de graphes de la bibliothèque GDS, notamment à charger des graphes en mémoire et à configurer les algorithmes.
Exécuter des algorithmes GDS est une leçon Neo4j Graph Database Fundamentals gratuite sur CoddyKit. Ceci est la leçon 2 sur 4. Tu peux lire la leçon complète ci-dessous gratuitement — puis la pratiquer en direct dans le navigateur avec un éditeur de code intégré et un tuteur IA 24/7. Elle fait partie du parcours d'apprentissage Neo4j Graph Database Fundamentals, et ta progression se synchronise sur le web et l'application CoddyKit. Le cours Neo4j Graph Database Fundamentals comprend 4 leçons au total.
Certaines parties de cette leçon n'ont pas encore été traduites et s'affichent en anglais.
GDS Algorithm Workflow
The Graph Data Science (GDS) library in Neo4j helps us run powerful graph algorithms. To use GDS, you generally follow a three-step process:
- Project: Load a subset of your graph into GDS's optimized in-memory store.
- Execute: Run an algorithm on this in-memory graph.
- Write Back: Optionally, write the results back to your Neo4j database.
Projecting Your Graph
Before running an algorithm, GDS needs to know which part of your database graph to analyze. This process is called graph projection.
You define which nodes and relationships, based on their labels and types, should be copied into GDS's fast in-memory representation. This makes algorithm execution much quicker.
Projecting Nodes Only
Let's project a simple graph containing only nodes with the label Person. We give our projected graph a name, like myGraph.
The gds.graph.project procedure creates this in-memory graph.
CALL gds.graph.project(
'myGraph',
'Person',
{}
) YIELD graphName, nodeCount, relationshipCount;Projecting Nodes and Relationships
More commonly, you'll project both nodes and relationships. Here, we project Person nodes and their KNOWS relationships.
We specify the node label and the relationship type. You can also add properties to the projection.
CALL gds.graph.project(
'socialGraph',
'Person',
'KNOWS'
) YIELD graphName, nodeCount, relationshipCount;Executing GDS Algorithms
Once your graph is projected, you can run various algorithms. GDS algorithms often have different execution modes:
- Stream: Returns results directly as a stream of rows. Great for immediate analysis.
- Stats: Returns only summary statistics about the algorithm's run.
- Write: Writes the results back to your Neo4j database as new properties or relationships.
PageRank Stream Example
Let's run the PageRank algorithm on our socialGraph in stream mode. PageRank helps identify influential nodes.
We use gds.pageRank.stream and pass the name of our projected graph.
CALL gds.pageRank.stream('socialGraph')
YIELD nodeId, score
RETURN gds.util.asNode(nodeId).name AS person, score
ORDER BY score DESC
LIMIT 5;Customizing Algorithm Settings
GDS algorithms are highly configurable. You can pass a map of parameters to fine-tune their behavior.
Common parameters include maxIterations, dampingFactor (for PageRank), or concurrency. Always check the GDS documentation for specific algorithm parameters.
PageRank with Custom Settings
Here, we run PageRank with a custom dampingFactor and limit the maxIterations. This gives you more control over the algorithm's execution and convergence.
CALL gds.pageRank.stream(
'socialGraph',
{
maxIterations: 10,
dampingFactor: 0.8
}
)
YIELD nodeId, score
RETURN gds.util.asNode(nodeId).name AS person, score
ORDER BY score DESC
LIMIT 5;Persisting Algorithm Results
Often, you'll want to store the results of an algorithm back into your Neo4j database. This allows you to query them later or use them in further analysis.
The write mode of GDS algorithms adds new properties to nodes or creates new relationships based on the algorithm's output.
Writing PageRank Scores
To write results, use the .write procedure, like gds.pageRank.write. You need to specify the property name where the score will be stored on the original nodes.
After running this, each Person node in your database will have a new property, pageRankScore.
CALL gds.pageRank.write(
'socialGraph',
{
writeProperty: 'pageRankScore'
}
)
YIELD nodeCount, ranIterations, didConverge;GDS Workflow Check
Which of the following are essential steps in the typical GDS algorithm workflow?
Running GDS Algorithms Recap
Great job! You've learned the core steps for running GDS algorithms:
- Projecting your graph into GDS memory using
gds.graph.project. - Executing algorithms in stream, stats, or write modes.
- Configuring algorithms with custom parameters.
- Writing back results to your Neo4j database for persistence.
Next, you'll explore advanced GDS pipelines and integration with machine learning!
Questions Fréquemment Posées
La leçon « Exécuter des algorithmes GDS » est-elle gratuite ?
Oui — le texte complet de « Exécuter des algorithmes GDS » est gratuit à lire ici sur le web. Pour la pratiquer de manière interactive (un éditeur de code intégré et un tuteur IA 24/7) et déverrouiller le reste du cours Neo4j Graph Database Fundamentals, passe à CoddyKit PRO. Le cours Neo4j Graph Database Fundamentals comprend 4 leçons au total.
Qu'est-ce que j'apprendrai dans « Exécuter des algorithmes GDS » ?
Apprenez à exécuter différents algorithmes de graphes de la bibliothèque GDS, notamment à charger des graphes en mémoire et à configurer les algorithmes. Tu pratiques Neo4j Graph Database Fundamentals avec du code pratique que tu exécutes directement dans le navigateur, et un tuteur IA 24/7 répond à tes questions au fur et à mesure que tu avances dans la leçon.
Dois-je avoir de l'expérience pour commencer Neo4j Graph Database Fundamentals ?
Aucune expérience préalable n'est requise. Neo4j Graph Database Fundamentals sur CoddyKit est structuré pour les débutants jusqu'aux apprenants avancés, donc tu peux commencer ici ou depuis le début et avancer à ton rythme. Ceci est la leçon 2 sur 4.
Combien de temps prend la leçon « Exécuter des algorithmes GDS » ?
La plupart des leçons CoddyKit prennent environ 5–10 minutes. Chacune est courte et interactive, tu progresses régulièrement et tu repiques exactement où tu t'es arrêté sur le web et l'app.
Peux-tu écrire et exécuter du code dans cette leçon Neo4j Graph Database Fundamentals ?
Oui. Chaque leçon Neo4j Graph Database Fundamentals inclut un éditeur de code intégré, tu écris et exécutes du vrai code directement dans ton navigateur et tu reçois des retours IA instantanés — aucune configuration locale requise.
Toutes les leçons de ce cours
- Introduction à la bibliothèque GDS
- Exécuter des algorithmes GDS
- Pipelines GDS et apprentissage automatique
- Représentations vectorielles de graphes avec GDS