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

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

Neptune ML 中的 Gremlin 节点回归查询

节点回归与节点分类类似,不同之处在于从回归模型中为每个节点推理的值都是数值。除了以下区别之外,您可以对节点回归使用与节点分类相同的 Gremlin 查询:

  • 同样,在 Neptune ML 中,节点指的是顶点。

  • properties() 步骤采用形式 properties().with("Neptune#ml.regression"),而不是 properties().with("Neptune#ml.classification")

  • "Neptune#ml.limit" 和 "Neptune#ml.threshold" 谓词不适用。

  • 对值进行筛选时,必须指定一个数值。

以下是一个示例顶点分类查询:

g.with("Neptune#ml.endpoint","node-regression-movie-lens-endpoint") .with("Neptune#ml.iamRoleArn", "arn:aws:iam::0123456789:role/sagemaker-role") .V("movie_1","movie_2","movie_3") .properties("revenue").with("Neptune#ml.regression")

您可以使用回归模型对推理的值进行筛选,如以下示例所示:

g.with("Neptune#ml.endpoint","node-regression-movie-lens-endpoint") .with("Neptune#ml.iamRoleArn","arn:aws:iam::0123456789:role/sagemaker-role") .V("movie_1","movie_2","movie_3") .properties("revenue").with("Neptune#ml.regression") .value().is(P.gte(1600000)) g.with("Neptune#ml.endpoint","node-regression-movie-lens-endpoint") .with("Neptune#ml.iamRoleArn","arn:aws:iam::0123456789:role/sagemaker-role") .V("movie_1","movie_2","movie_3") .properties("revenue").with("Neptune#ml.regression") .hasValue(P.lte(1600000D))

在节点回归查询中使用归纳推理

假设您要在 Jupyter 笔记本的现有图形中添加一个新节点,如下所示:

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

然后,您可以使用归纳推理查询来获得考虑了新节点的评级:

%%gremlin g.with("Neptune#ml.endpoint", "nr-ep") .with("Neptune#ml.iamRoleArn", "arn:aws:iam::123456789012:role/NeptuneMLRole") .V('101').properties("rating") .with("Neptune#ml.regression") .with("Neptune#ml.inductiveInference")

由于查询不是确定性的,因此如果您根据邻域运行它多次,它返回的结果可能会有所不同:

# First time ==>vp[rating->9.1] # Second time ==>vp[rating->8.9]

如果您需要更一致的结果,可以使查询具有确定性:

%%gremlin g.with("Neptune#ml.endpoint", "nc-ep") .with("Neptune#ml.iamRoleArn", "arn:aws:iam::123456789012:role/NeptuneMLRole") .V('101').properties("rating") .with("Neptune#ml.regression") .with("Neptune#ml.inductiveInference") .with("Neptune#ml.deterministic")

现在,每次的结果将大致相同:

# First time ==>vp[rating->9.1] # Second time ==>vp[rating->9.1]