Neo4j Graph Database Fundamentals · บทเรียน

การเรียกใช้อัลกอริทึม GDS

เรียนรู้การเรียกใช้อัลกอริทึมกราฟต่าง ๆ จากไลบรารี GDS รวมถึงการโหลดกราฟเข้าสู่หน่วยความจำและการกำหนดค่าอัลกอริทึม

บทเรียน 2 จาก 412 ขั้นตอน

การเรียกใช้อัลกอริทึม GDS เป็นบทเรียน Neo4j Graph Database Fundamentals ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Neo4j Graph Database Fundamentals และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Neo4j Graph Database Fundamentals มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

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!

เริ่มต้นได้ฟรี

เรียนรู้ Neo4j Graph Database Fundamentals ด้วย AI tutor — ฟรี

เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป

คอร์ส
12
บทเรียน
48

คำถามที่พบบ่อย

บทเรียน “การเรียกใช้อัลกอริทึม GDS” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การเรียกใช้อัลกอริทึม GDS” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Neo4j Graph Database Fundamentals ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Neo4j Graph Database Fundamentals มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การเรียกใช้อัลกอริทึม GDS”

เรียนรู้การเรียกใช้อัลกอริทึมกราฟต่าง ๆ จากไลบรารี GDS รวมถึงการโหลดกราฟเข้าสู่หน่วยความจำและการกำหนดค่าอัลกอริทึม คุณปฏิบัติ Neo4j Graph Database Fundamentals ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Neo4j Graph Database Fundamentals หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Neo4j Graph Database Fundamentals บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน

บทเรียน “การเรียกใช้อัลกอริทึม GDS” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Neo4j Graph Database Fundamentals นี้ได้ไหม

ได้ บทเรียน Neo4j Graph Database Fundamentals ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. บทนำสู่ไลบรารี GDS
  2. การเรียกใช้อัลกอริทึม GDS
  3. กระบวนการส่งข้อมูล GDS และการเรียนรู้ของเครื่อง
  4. การฝังกราฟด้วย GDS
← กลับไปที่ Neo4j Graph Database Fundamentals