GDS 管道与机器学习
了解如何在 GDS 中构建和管理图数据科学管道,并将其与机器学习工作流程集成
GDS 管道与机器学习 是 CoddyKit 上的免费 Neo4j Graph Database Fundamentals 课时。 这是第 3 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Neo4j Graph Database Fundamentals 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Neo4j Graph Database Fundamentals 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
What are GDS Pipelines?
Welcome to GDS Pipelines! In the Neo4j Graph Data Science (GDS) library, a pipeline is a structured workflow for common graph data science tasks.
Think of it as a blueprint that defines a sequence of steps, from feature engineering using graph algorithms to training and deploying machine learning models.
Why Use GDS Pipelines?
GDS Pipelines offer several key benefits:
- Reproducibility: Define your entire workflow once and reuse it.
- Automation: Streamline complex tasks involving multiple graph algorithms and ML steps.
- Operationalization: Easily deploy graph-based machine learning models for continuous prediction.
They help bridge the gap between experimentation and production.
Creating a Prediction Pipeline
One common pipeline type is the Node Property Prediction Pipeline. This helps predict a specific property on nodes based on other node features and graph structure.
Let's create an empty pipeline named 'myChurnPrediction':
CALL gds.pipeline.nodePropertyPrediction.create('myChurnPrediction')
YIELD pipeline
RETURN pipeline.name AS name, pipeline.type AS typeProjecting Your Graph Data
Before using a pipeline, you need to project your graph into GDS memory. This makes nodes and relationships accessible for algorithms and features.
Here, we project a simple 'User' graph with 'KNOWS' relationships:
CALL gds.graph.project(
'mySocialGraph',
'User',
{ KNOWS: { orientation: 'UNDIRECTED' } }
)
YIELD graphName, nodeCount, relationshipCount
RETURN graphName, nodeCount, relationshipCountAdding Node Property Features
Pipelines allow you to specify which existing node properties should be used as features for your machine learning model. These are direct attributes of your nodes.
Let's add 'age' and 'income' properties as features to our pipeline:
CALL gds.pipeline.nodePropertyPrediction.addNodePropertySteps('myChurnPrediction', {
nodeProperties: ['age', 'income']
})
YIELD pipeline
RETURN pipeline.name, pipeline.nodePropertyStepsIntegrating Graph Algorithm Features
The real power of GDS pipelines is integrating graph algorithm results as features. These capture structural insights that simple node properties can't.
We can add PageRank scores as a feature to our pipeline:
CALL gds.pipeline.nodePropertyPrediction.addPageRank('myChurnPrediction', {
maxIterations: 10,
dampingFactor: 0.85,
mutateProperty: 'pageRankScore' // This becomes a feature
})
YIELD pipeline
RETURN pipeline.name, pipeline.pageRankStepsConfiguring the Machine Learning Model
After defining your features, you specify the machine learning model that will perform the prediction. GDS supports various models like Logistic Regression, Random Forest, and GNNs.
Let's add a Logistic Regression model to predict 'isChurned':
CALL gds.pipeline.nodePropertyPrediction.addLogisticRegression('myChurnPrediction', {
targetProperty: 'isChurned', // The node property we want to predict
maxIterations: 100,
penalty: 'l2'
})
YIELD pipeline
RETURN pipeline.name, pipeline.logisticRegressionStepsTraining Your GDS Pipeline
With features and a model defined, you can now train the pipeline. This executes all feature generation steps, then trains the specified ML model on the generated features.
We'll train our pipeline on 'mySocialGraph' and name the resulting model 'churnPredictionModel':
CALL gds.pipeline.nodePropertyPrediction.train('myChurnPrediction', {
modelName: 'churnPredictionModel',
graphName: 'mySocialGraph',
nodeLabels: ['User'],
randomSeed: 42
})
YIELD modelInfo
RETURN modelInfo.modelName AS modelName, modelInfo.trainingMetrics.f1Score.weighted AS f1ScoreMaking Predictions with the Model
Once trained, your model (which is part of the pipeline) can be used to generate predictions on your graph data. You can either stream results or mutate the graph with new properties.
Let's stream predictions for our 'churnPredictionModel':
CALL gds.pipeline.nodePropertyPrediction.predict.stream('churnPredictionModel', {
graphName: 'mySocialGraph',
nodeLabels: ['User'],
topN: 1 // Get the top predicted class
})
YIELD nodeId, predictedProperty, probability
RETURN gds.util.asNode(nodeId).name AS user, predictedProperty, probability
LIMIT 5Managing Your Pipelines
You can list all active pipelines and their configurations using gds.pipeline.list(). When a pipeline is no longer needed, you can remove it with gds.pipeline.drop().
Let's see the pipelines we currently have:
CALL gds.pipeline.list()
YIELD name, type, creationTime
RETURN name, type, creationTimeGDS Pipeline Components
A GDS pipeline combines various steps to create a complete data science workflow. Which of the following are valid components or steps you can add to a GDS Node Property Prediction Pipeline?
Recap: Pipelines for ML
Great job! You've learned how GDS Pipelines provide a structured and reproducible way to integrate graph algorithms with machine learning workflows.
- Pipelines define a sequence of steps.
- They combine feature engineering (from existing properties and graph algorithms) with ML model training.
- They enable efficient prediction and operationalization of graph-based insights.
Keep exploring GDS to unlock more advanced graph analytics!
用 AI 导师学习 Neo4j Graph Database Fundamentals — 免费
在浏览器中编写并运行真实代码,获得全天候 AI 导师的即时帮助,并在网页或应用中继续学习。
- 课程
- 12
- 课程
- 48
常见问题解答
「GDS 管道与机器学习」课时是免费的吗?
是的 — 「GDS 管道与机器学习」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Neo4j Graph Database Fundamentals 课程的其余内容,请升级到 CoddyKit PRO。 Neo4j Graph Database Fundamentals 课程共包含 4 节课。
「GDS 管道与机器学习」这节课中我会学到什么?
了解如何在 GDS 中构建和管理图数据科学管道,并将其与机器学习工作流程集成 你通过在浏览器中直接运行的动手代码来练习 Neo4j Graph Database Fundamentals,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Neo4j Graph Database Fundamentals 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Neo4j Graph Database Fundamentals 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 3 节课,共 4 节。
「GDS 管道与机器学习」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Neo4j Graph Database Fundamentals 课中编写并运行代码吗?
能。每节 Neo4j Graph Database Fundamentals 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。
此课程中的所有课时
- GDS 库简介
- 运行 GDS 算法
- GDS 管道与机器学习
- 使用 GDS 进行图嵌入