本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
Neptune ML 中的 Gremlin 邊緣迴歸查詢
邊緣迴歸類似於邊緣分類,不同之處在於從 ML 模型推斷出的值是數值。對於邊緣迴歸,Neptune ML 支援與分類相同的查詢。
需要注意的要點如下:
您必須使用 ML 述詞
"Neptune#ml.regression"
,針對此使用案例設定properties()
步驟。"Neptune#ml.limit"
和"Neptune#ml.threshold"
述詞不適用於此使用案例。如需根據值進行過濾,您需要將該值指定為數值。
Gremlin 邊緣迴歸查詢的語法
對於簡單圖形,其中 User
是前端節點、Movie
是尾端節點,以及 Rated
是連接它們的邊緣,以下是一個範例邊緣迴歸查詢,其會尋找邊緣 Rated
的數值評分值,在這裡稱為分數:
g.with("Neptune#ml.endpoint","edge-regression-movie-lens-endpoint") .with("Neptune#ml.iamRoleArn","arn:aws:iam::0123456789:role/sagemaker-role") .E("rating_1","rating_2","rating_3") .properties("score").with("Neptune#ml.regression")
您也可以根據從 ML 迴歸模型推斷出的值進行篩選。對於由 "rating_1"
、"rating_2"
和 "rating_3"
所識別的現有 Rated
邊緣 (從 User
到 Movie
),其中這些評分不存在邊緣屬性 Score
,您可以使用如下查詢來推斷邊緣的 Score
,其中它大於或等於 9:
g.with("Neptune#ml.endpoint","edge-regression-movie-lens-endpoint") .with("Neptune#ml.iamRoleArn","arn:aws:iam::0123456789:role/sagemaker-role") .E("rating_1","rating_2","rating_3") .properties("score").with("Neptune#ml.regression") .value().is(P.gte(9))
在邊緣迴歸查詢中使用歸納推論
假設您要在 Jupyter 筆記本中將新邊緣新增至現有圖形,如下所示:
%%gremlin g.V('1').as('fromV') .V('2').as('toV') .addE('eLabel1').from('fromV').to('toV').property(id, 'e101')
然後,您可以使用歸納推論查詢,來取得考慮到新邊緣的分數:
%%gremlin g.with("Neptune#ml.endpoint", "er-ep") .with("Neptune#ml.iamRoleArn", "arn:aws:iam::123456789012:role/NeptuneMLRole") .E('e101').properties("score") .with("Neptune#ml.regression") .with("Neptune#ml.inductiveInference")
因為查詢不具確定性,所以如果根據隨機鄰域多次執行該查詢,結果將會有些不同:
# First time ==>ep[score->96] # Second time ==>ep[score->91]
如果需要更一致的結果,您可以使查詢具有確定性:
%%gremlin g.with("Neptune#ml.endpoint", "er-ep") .with("Neptune#ml.iamRoleArn", "arn:aws:iam::123456789012:role/NeptuneMLRole") .E('e101').properties("score") .with("Neptune#ml.regression") .with("Neptune#ml.inductiveInference") .with("Neptune#ml.deterministic")
現在,每次執行查詢時,結果都會或多或少相同:
# First time ==>ep[score->96] # Second time ==>ep[score->96]