

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

# Kueri klasifikasi simpul Gremlin di Neptunus ML
<a name="machine-learning-gremlin-vertex-classification-queries"></a>

Untuk klasifikasi node Gremlin di Neptunus ML:
+ Model ini dilatih pada satu properti dari vertex. Rangkain nilai unik dari properti ini disebut sebagai satu set kelas simpul, atau hanya, kelas.
+ Kelas simpul atau nilai properti kategoris dari properti vertex ini dapat disimpulkan dari model klasifikasi simpul. Hal ini berguna di mana properti ini belum melekat pada simpul.
+ Dalam rangka untuk mengambil satu kelas atau lebih dari model klasifikasi simpul, Anda perlu menggunakan langkah `with()` dengan predikat `Neptune#ml.classification` untuk mengonfigurasi langkah `properties()`. Format output mirip dengan apa yang Anda harapkan jika format adalah properti vertex.

**catatan**  
Klasifikasi node hanya bekerja dengan nilai properti string. Itu berarti bahwa nilai properti numerik seperti `0` atau tidak `1` didukung, meskipun string setara `"0"` dan adalah. `"1"` Demikian pula, nilai properti Boolean `true` dan `false` tidak berfungsi, tetapi `"true"` dan `"false"` lakukan.

Berikut adalah contoh kueri klasifikasi node:

```
g.with( "Neptune#ml.endpoint","node-classification-movie-lens-endpoint" )
 .with( "Neptune#ml.iamRoleArn","arn:aws:iam::0123456789:role/sagemaker-role" )
 .with( "Neptune#ml.limit", 2 )
 .with( "Neptune#ml.threshold", 0.5D )
 .V( "movie_1", "movie_2", "movie_3" )
 .properties("genre").with("Neptune#ml.classification")
```

Output dari kueri ini akan terlihat seperti berikut ini:

```
==>vp[genre->Action]
==>vp[genre->Crime]
==>vp[genre->Comedy]
```

Dalam query di atas, langkah `V()` dan `properties()` digunakan sebagai berikut:

Langkah `V()` berisi rangkaian vertex di mana Anda ingin mengambil kelas dari model klasifikasi node:

```
 .V( "movie_1", "movie_2", "movie_3" )
```

`properties()`Langkah berisi kunci di mana model dilatih, dan `.with("Neptune#ml.classification")` harus menunjukkan bahwa ini adalah kueri inferensi MS klasifikasi node.

Kunci properti ganda saat ini tidak didukung di langkah `properties().with("Neptune#ml.classification")`. Sebagai contoh, hasil kueri berikut dalam pengecualian:

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

Untuk pesan kesalahan tertentu, lihat [daftar pengecualian Neptune ML](machine-learning-gremlin-exceptions.md).

Langkah `properties().with("Neptune#ml.classification")` dapat digunakan dalam kombinasi dengan semua langkah-langkah berikut:
+ `value()`
+ `value().is()`
+ `hasValue()`
+ `has(value,"")`
+ `key()`
+ `key().is()`
+ `hasKey()`
+ `has(key,"")`
+ `path()`

## Kueri klasifikasi simpul lainnya
<a name="machine-learning-gremlin-node-class-other-queries"></a>

Jika titik akhir inferensi dan peran IAM yang sesuai telah disimpan dalam grup parameter cluster DB Anda, kueri klasifikasi simpul dapat sesederhana ini:

```
g.V("movie_1", "movie_2", "movie_3").properties("genre").with("Neptune#ml.classification")
```

Anda dapat mencampur properti vertex dan kelas dalam kueri menggunakan langkah `union()`:

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

Anda juga dapat membuat kueri tak terbatas seperti ini:

```
g.with("Neptune#ml.endpoint","node-classification-movie-lens-endpoint")
 .with("Neptune#ml.iamRoleArn","arn:aws:iam::0123456789:role/sagemaker-role")
 .V()
 .properties("genre").with("Neptune#ml.classification")
```

Anda dapat mengambil kelas simpul bersama-sama dengan vertex menggunakan langkah `select()` bersama dengan langkah `as()`:

```
g.with("Neptune#ml.endpoint","node-classification-movie-lens-endpoint")
 .with("Neptune#ml.iamRoleArn","arn:aws:iam::0123456789:role/sagemaker-role")
 .V( "movie_1", "movie_2", "movie_3" ).as("vertex")
 .properties("genre").with("Neptune#ml.classification").as("properties")
 .select("vertex","properties")
```

Anda juga dapat menyaring pada kelas simpul, seperti yang digambarkan dalam contoh-contoh ini:

```
g.with("Neptune#ml.endpoint", "node-classification-movie-lens-endpoint")
 .with("Neptune#ml.iamRoleArn","arn:aws:iam::0123456789:role/sagemaker-role")
 .V( "movie_1", "movie_2", "movie_3" )
 .properties("genre").with("Neptune#ml.classification")
 .has(value, "Horror")

g.with("Neptune#ml.endpoint","node-classification-movie-lens-endpoint")
 .with("Neptune#ml.iamRoleArn","arn:aws:iam::0123456789:role/sagemaker-role")
 .V( "movie_1", "movie_2", "movie_3" )
 .properties("genre").with("Neptune#ml.classification")
 .has(value, P.eq("Action"))

g.with("Neptune#ml.endpoint","node-classification-movie-lens-endpoint")
 .with("Neptune#ml.iamRoleArn","arn:aws:iam::0123456789:role/sagemaker-role")
 .V( "movie_1", "movie_2", "movie_3" )
 .properties("genre").with("Neptune#ml.classification")
 .has(value, P.within("Action", "Horror"))
```

Anda bisa mendapatkan skor kepercayaan klasifikasi node menggunakan `Neptune#ml.score` predikat:

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

Responsnya akan terlihat seperti ini:

```
==>vp[genre->Action]
==>vp[Neptune#ml.score->0.01234567]
==>vp[genre->Crime]
==>vp[Neptune#ml.score->0.543210]
==>vp[genre->Comedy]
==>vp[Neptune#ml.score->0.10101]
```

## Menggunakan inferensi induktif dalam kueri klasifikasi node
<a name="machine-learning-gremlin-node-class-inductive"></a>

Misalkan Anda menambahkan simpul baru ke grafik yang ada, di buku catatan Jupyter, seperti ini:

```
%%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')
```

Anda kemudian dapat menggunakan kueri inferensi induktif untuk mendapatkan genre dan skor kepercayaan yang mencerminkan node baru:

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

Namun, jika Anda menjalankan kueri beberapa kali, Anda mungkin mendapatkan hasil yang agak berbeda:

```
# First time
==>vp[genre->Action]
==>vp[Neptune#ml.score->0.12345678]

# Second time
==>vp[genre->Action]
==>vp[Neptune#ml.score->0.21365921]
```

Anda dapat membuat kueri deterministik yang sama:

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

Dalam hal ini, hasilnya kira-kira sama setiap saat:

```
# First time
==>vp[genre->Action]
==>vp[Neptune#ml.score->0.12345678]
# Second time
==>vp[genre->Action]
==>vp[Neptune#ml.score->0.12345678]
```