Neptune ML 中的 Gremlin 边缘回归查询 - Amazon Neptune
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

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 边缘(从 UserMovie),如果这些评分不存在边缘属性 Score,则可以使用如下查询对于其大于或等于 9 的边缘推理 Score

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]