

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

# Neptune ML 中的 Gremlin 節點迴歸查詢
<a name="machine-learning-gremlin-vertex-regression-queries"></a>

節點迴歸類似於節點分類，不同之處在於從每個節點的迴歸模型推斷出的值是數值。您可以使用與節點分類相同的 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))
```

## 在節點迴歸查詢中使用歸納推論
<a name="machine-learning-gremlin-node-regress-inductive"></a>

假設您要在 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]
```