選取您的 Cookie 偏好設定

我們使用提供自身網站和服務所需的基本 Cookie 和類似工具。我們使用效能 Cookie 收集匿名統計資料,以便了解客戶如何使用我們的網站並進行改進。基本 Cookie 無法停用,但可以按一下「自訂」或「拒絕」以拒絕效能 Cookie。

如果您同意,AWS 與經核准的第三方也會使用 Cookie 提供實用的網站功能、記住您的偏好設定,並顯示相關內容,包括相關廣告。若要接受或拒絕所有非必要 Cookie,請按一下「接受」或「拒絕」。若要進行更詳細的選擇,請按一下「自訂」。

在 Neptune ML 中使用連結預測模型進行 Gremlin 連結預測查詢

焦點模式
在 Neptune ML 中使用連結預測模型進行 Gremlin 連結預測查詢 - Amazon Neptune

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

連結預測模型可以解決如下問題:

  • 前端節點預測:鑑於頂點和邊緣類型,該頂點可能從哪些頂點連結?

  • 尾端節點預測:鑑於頂點和邊緣標籤,該頂點可能連結至哪些頂點?

注意

Neptune ML 中尚未支援邊緣預測。

對於下面範例,考慮其中頂點 UserMovie 是由邊緣 Rated 連結的簡單圖形。

以下是範例前端節點預測查詢,用來預測最有可能評分電影 ("movie_1""movie_2""movie_3") 的前五名使用者:

g.with("Neptune#ml.endpoint","node-prediction-movie-lens-endpoint") .with("Neptune#ml.iamRoleArn","arn:aws:iam::0123456789:role/sagemaker-role") .with("Neptune#ml.limit", 5) .V("movie_1", "movie_2", "movie_3") .in("rated").with("Neptune#ml.prediction").hasLabel("user")

以下是用於尾端節點預測的類似查詢,用來預測使用者 "user_1" 可能評分的前五名電影:

g.with("Neptune#ml.endpoint","node-prediction-movie-lens-endpoint") .with("Neptune#ml.iamRoleArn","arn:aws:iam::0123456789:role/sagemaker-role") .V("user_1") .out("rated").with("Neptune#ml.prediction").hasLabel("movie")

邊緣標籤和預測的頂點標籤都是必要的。如果省略其中一個,則會擲出例外狀況。例如,以下查詢沒有預測的頂點標籤,其會擲回例外狀況:

g.with("Neptune#ml.endpoint","node-prediction-movie-lens-endpoint") .with("Neptune#ml.iamRoleArn","arn:aws:iam::0123456789:role/sagemaker-role") .V("user_1") .out("rated").with("Neptune#ml.prediction")

同樣地,沒有邊緣標籤的下列查詢也會擲回例外狀況:

g.with("Neptune#ml.endpoint","node-prediction-movie-lens-endpoint") .with("Neptune#ml.iamRoleArn","arn:aws:iam::0123456789:role/sagemaker-role") .V("user_1") .out().with("Neptune#ml.prediction").hasLabel("movie")

如需這些例外狀況傳回的特定錯誤訊息,請參閱 Neptune ML 例外狀況清單

您可以使用 select() 步驟搭配 as() 步驟,以同時輸出預測的頂點與輸入頂點:

g.with("Neptune#ml.endpoint","node-prediction-movie-lens-endpoint") .with("Neptune#ml.iamRoleArn","arn:aws:iam::0123456789:role/sagemaker-role") .V("movie_1").as("source") .in("rated").with("Neptune#ml.prediction").hasLabel("user").as("target") .select("source","target") g.with("Neptune#ml.endpoint","node-prediction-movie-lens-endpoint") .with("Neptune#ml.iamRoleArn","arn:aws:iam::0123456789:role/sagemaker-role") .V("user_1").as("source") .out("rated").with("Neptune#ml.prediction").hasLabel("movie").as("target") .select("source","target")

您可以進行無限制查詢,如下所示:

g.with("Neptune#ml.endpoint","node-prediction-movie-lens-endpoint") .with("Neptune#ml.iamRoleArn","arn:aws:iam::0123456789:role/sagemaker-role") .V("user_1") .out("rated").with("Neptune#ml.prediction").hasLabel("movie") g.with("Neptune#ml.endpoint","node-prediction-movie-lens-endpoint") .with("Neptune#ml.iamRoleArn","arn:aws:iam::0123456789:role/sagemaker-role") .V("movie_1") .in("rated").with("Neptune#ml.prediction").hasLabel("user")

假設您要在 Jupyter 筆記本中將新節點新增至現有圖形,如下所示:

%%gremlin g.addV('label1').property(id,'101').as('newV1') .addV('label2').property(id,'102').as('newV2') .V('1').as('oldV1') .V('2').as('oldV2') .addE('eLabel1').from('newV1').to('oldV1') .addE('eLabel2').from('oldV2').to('newV2')

然後,您可以使用歸納推論查詢來預測前端節點,同時考慮到新節點:

%%gremlin g.with("Neptune#ml.endpoint", "lp-ep") .with("Neptune#ml.iamRoleArn", "arn:aws:iam::123456789012:role/NeptuneMLRole") .V('101').out("eLabel1") .with("Neptune#ml.prediction") .with("Neptune#ml.inductiveInference") .hasLabel("label2")

結果:

==>V[2]

同樣地,您可以使用歸納推論查詢來預測尾端節點,同時考慮到新節點:

%%gremlin g.with("Neptune#ml.endpoint", "lp-ep") .with("Neptune#ml.iamRoleArn", "arn:aws:iam::123456789012:role/NeptuneMLRole") .V('102').in("eLabel2") .with("Neptune#ml.prediction") .with("Neptune#ml.inductiveInference") .hasLabel("label1")

結果:

==>V[1]

在本頁面

下一個主題:

例外狀況清單

上一個主題:

邊緣迴歸
隱私權網站條款Cookie 偏好設定
© 2025, Amazon Web Services, Inc.或其附屬公司。保留所有權利。