使用 GDS 进行图嵌入
学习 Graph Data Science 如何生成节点嵌入,将图结构转换为供机器学习使用的向量。
使用 GDS 进行图嵌入 是 CoddyKit 上的免费 Neo4j Graph Database Fundamentals 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Neo4j Graph Database Fundamentals 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Neo4j Graph Database Fundamentals 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
From Graphs to Vectors
Machine learning models work with numbers, not graph topology. Graph embeddings convert each node into a fixed-length vector that captures its position and neighborhood.
Why Embeddings Help
Once nodes are vectors, you can feed them into classifiers, clustering, and similarity search. Similar nodes end up close together in vector space.
Projecting a Graph
Embeddings run on an in-memory graph projection in GDS. First project the nodes and relationships you care about.
CALL gds.graph.project(
'embedGraph',
'Person',
'FRIEND'
);FastRP
FastRP (Fast Random Projection) is a quick, scalable embedding algorithm. It is a great default for large graphs.
CALL gds.fastRP.stream('embedGraph', { embeddingDimension: 128 })
YIELD nodeId, embedding
RETURN gds.util.asNode(nodeId).name AS name, embedding
LIMIT 5;Node2Vec
Node2Vec uses biased random walks to learn embeddings that balance local and global structure. It is slower but often richer than FastRP.
CALL gds.node2vec.stream('embedGraph', { embeddingDimension: 128, walkLength: 80 })
YIELD nodeId, embedding
RETURN nodeId, embedding
LIMIT 5;GraphSAGE
GraphSAGE is an inductive method: it learns a function that can embed even new nodes not seen during training, using their features.
Choosing Dimensions
The embedding dimension trades expressiveness for cost. Common values are 64, 128, or 256. Larger is more detailed but heavier.
Writing Embeddings Back
Use the write mode to store embeddings as a node property, so other queries and tools can use them.
CALL gds.fastRP.write('embedGraph', {
embeddingDimension: 128,
writeProperty: 'embedding'
});Using Embeddings for Similarity
With vectors stored, compute cosine similarity between embeddings to find nodes that are structurally alike.
MATCH (a:Person {name: 'Alice'}), (b:Person)
WHERE a <> b
RETURN b.name, gds.similarity.cosine(a.embedding, b.embedding) AS sim
ORDER BY sim DESC LIMIT 5;Embeddings in ML Pipelines
Embeddings are powerful features for GDS machine learning pipelines: node classification and link prediction both benefit from them.
Choosing an Algorithm
Use FastRP for speed at scale, Node2Vec for richer structure, and GraphSAGE when you must embed unseen nodes.
Quick Check
Test your embeddings knowledge.
Recap
You learned graph embeddings in GDS:
- Embeddings turn nodes into vectors
- FastRP is fast and scalable
- Node2Vec uses biased random walks
- GraphSAGE handles unseen nodes
- Write embeddings back and use them in ML pipelines
常见问题解答
「使用 GDS 进行图嵌入」课时是免费的吗?
是的 — 「使用 GDS 进行图嵌入」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Neo4j Graph Database Fundamentals 课程的其余内容,请升级到 CoddyKit PRO。 Neo4j Graph Database Fundamentals 课程共包含 4 节课。
「使用 GDS 进行图嵌入」这节课中我会学到什么?
学习 Graph Data Science 如何生成节点嵌入,将图结构转换为供机器学习使用的向量。 你通过在浏览器中直接运行的动手代码来练习 Neo4j Graph Database Fundamentals,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Neo4j Graph Database Fundamentals 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Neo4j Graph Database Fundamentals 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。
「使用 GDS 进行图嵌入」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Neo4j Graph Database Fundamentals 课中编写并运行代码吗?
能。每节 Neo4j Graph Database Fundamentals 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。
此课程中的所有课时
- GDS 库简介
- 运行 GDS 算法
- GDS 管道与机器学习
- 使用 GDS 进行图嵌入