

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# Neptune ML의 Gremlin 엣지 분류 쿼리
<a name="machine-learning-gremlin-edge-classification-queries"></a>

Neptune ML의 Gremlin 엣지 분류의 경우:
+ 모델은 엣지의 한 속성에 대해 훈련됩니다. 이 속성의 고유한 값 세트를 클래스 세트라고 합니다.
+ 엣지의 클래스 또는 범주형 속성 값은 엣지 분류 모델에서 유추할 수 있으며, 이는 이 속성이 아직 엣지에 연결되지 않은 경우에 유용합니다.
+ 엣지 분류 모델에서 하나 이상의 클래스를 가져오려면 조건자 `"Neptune#ml.classification"`과 함께 `with()` 단계를 사용하여 `properties()` 단계를 구성해야 합니다. 출력 형식은 엣지 속성일 때 예상할 수 있는 것과 비슷합니다.

**참고**  
엣지 분류는 문자열 속성 값에서만 작동합니다. 즉, 문자열에 해당하는 항목인 `"0"` 및 `"1"`은 지원되지만, `0` 또는 `1`과 같은 숫자 속성 값은 지원되지 않습니다. 마찬가지로, 부울 속성 값 `true` 및 `false`도 작동하지 않지만, `"true"` 및 `"false"`는 작동합니다.

다음은 `Neptune#ml.score` 조건자를 사용하여 신뢰도 점수를 요청하는 엣지 분류 쿼리의 예제입니다.

```
g.with("Neptune#ml.endpoint","edge-classification-movie-lens-endpoint")
 .with("Neptune#ml.iamRoleArn","arn:aws:iam::0123456789:role/sagemaker-role")
 .E("relationship_1","relationship_2","relationship_3")
 .properties("knows_by", "Neptune#ml.score").with("Neptune#ml.classification")
```

응답은 다음과 같습니다.

```
==>p[knows_by->"Family"]
==>p[Neptune#ml.score->0.01234567]
==>p[knows_by->"Friends"]
==>p[Neptune#ml.score->0.543210]
==>p[knows_by->"Colleagues"]
==>p[Neptune#ml.score->0.10101]
```

## Gremlin 엣지 분류 쿼리의 구문
<a name="machine-learning-gremlin-edge-classification-syntax"></a>

`User`가 헤드 및 테일 노드이고 `Relationship`이 이들을 연결하는 엣지인 단순 그래프의 경우 엣지 분류 쿼리의 예제는 다음과 같습니다.

```
g.with("Neptune#ml.endpoint","edge-classification-social-endpoint")
 .with("Neptune#ml.iamRoleArn","arn:aws:iam::0123456789:role/sagemaker-role")
 .E("relationship_1","relationship_2","relationship_3")
 .properties("knows_by").with("Neptune#ml.classification")
```

이 쿼리의 출력은 다음과 같습니다.

```
==>p[knows_by->"Family"]
==>p[knows_by->"Friends"]
==>p[knows_by->"Colleagues"]
```

위 쿼리에서는 `E()` 및 `properties()` 단계가 다음과 같이 사용됩니다.
+ 이 `E()` 단계에는 엣지 분류 모델에서 클래스를 가져오려는 엣지 세트가 포함됩니다.

  ```
  .E("relationship_1","relationship_2","relationship_3")
  ```
+ `properties()` 단계에는 모델이 훈련된 키가 포함되어 있으며, 엣지 분류 ML 추론 쿼리임을 나타내는 `.with("Neptune#ml.classification")`가 있습니다.

여러 속성 키는 현재 `properties().with("Neptune#ml.classification")` 단계에서 지원되지 않습니다. 예를 들어, 다음 쿼리를 실행하면 예외가 발생합니다.

```
g.with("Neptune#ml.endpoint","edge-classification-social-endpoint")
 .with("Neptune#ml.iamRoleArn","arn:aws:iam::0123456789:role/sagemaker-role")
 .E("relationship_1","relationship_2","relationship_3")
 .properties("knows_by", "other_label").with("Neptune#ml.classification")
```

구체적인 오류 메시지는 [Neptune ML Gremlin 추론 쿼리의 예외 목록](machine-learning-gremlin-exceptions.md)을 참조하세요.

`properties().with("Neptune#ml.classification")` 단계는 다음 단계 중 하나와 함께 사용할 수 있습니다.
+ `value()`
+ `value().is()`
+ `hasValue()`
+ `has(value,"")`
+ `key()`
+ `key().is()`
+ `hasKey()`
+ `has(key,"")`
+ `path()`

## 엣지 분류 쿼리에서 유도 추론 사용
<a name="machine-learning-gremlin-edge-class-inductive"></a>

Jupyter Notebook의 기존 그래프에 다음과 같이 새 엣지를 추가한다고 가정해 보겠습니다.

```
%%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", "ec-ep")
 .with("Neptune#ml.iamRoleArn", "arn:aws:iam::123456789012:role/NeptuneMLRole")
 .E('e101').properties("scale", "Neptune#ml.score")
 .with("Neptune#ml.classification")
 .with("Neptune#ml.inductiveInference")
```

쿼리는 결정적이지 않기 때문에 무작위 주변 환경에 따라 여러 번 실행하면 결과가 약간 달라질 수 있습니다.

```
# First time
==>vp[scale->Like]
==>vp[Neptune#ml.score->0.12345678]

# Second time
==>vp[scale->Like]
==>vp[Neptune#ml.score->0.21365921]
```

좀 더 일관된 결과가 필요한 경우 쿼리를 결정적으로 만들면 됩니다.

```
%%gremlin
g.with("Neptune#ml.endpoint", "ec-ep")
 .with("Neptune#ml.iamRoleArn", "arn:aws:iam::123456789012:role/NeptuneMLRole")
 .E('e101').properties("scale", "Neptune#ml.score")
 .with("Neptune#ml.classification")
 .with("Neptune#ml.inductiveInference")
 .with("Neptune#ml.deterministic")
```

이제 쿼리를 실행할 때마다 결과는 거의 동일합니다.

```
# First time
==>vp[scale->Like]
==>vp[Neptune#ml.score->0.12345678]

# Second time
==>vp[scale->Like]
==>vp[Neptune#ml.score->0.12345678]
```