

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

# IP Insights 資料格式
<a name="ip-insights-data-formats"></a>

本節提供 IP Insights 演算法在訓練和推論期間，所使用可用輸入和輸出資料格式的範例。

**Topics**
+ [IP Insights 訓練資料格式](ip-insights-training-data-formats.md)
+ [IP Insights 推論資料格式](ip-insights-inference-data-formats.md)

# IP Insights 訓練資料格式
<a name="ip-insights-training-data-formats"></a>

以下是 IP Insights 演算法的可用資料輸入格式。Amazon SageMaker AI 內建演算法會遵循[用於訓練的一般資料格式](cdf-training.md)中所述的常見輸入訓練格式。但是，SageMaker AI IP Insights 演算法目前只支援 CSV 資料輸入格式。

## IP Insights 訓練資料輸入格式
<a name="ip-insights-training-input-format-requests"></a>

### 輸入：CSV
<a name="ip-insights-input-csv"></a>

CSV 檔案必須擁有兩個欄。第一欄是一個不透明字串，對應到實體的唯一識別符。第二欄則是實體地址事件的 IPv4 地址，以小數點表示法表示。

content-type：text/csv

```
entity_id_1, 192.168.1.2
entity_id_2, 10.10.1.2
```

# IP Insights 推論資料格式
<a name="ip-insights-inference-data-formats"></a>

以下是 IP Insights 演算法的可用輸入及輸出格式。Amazon SageMaker AI 內建演算法會遵循[推論的一般資料格式](cdf-inference.md)中所述的常見輸入推論格式。但是，SageMaker AI IP Insights 演算法目前不支援 RecordIO 格式。

## IP Insights 輸入請求格式
<a name="ip-insights-input-format-requests"></a>

### 輸入：CSV 格式
<a name="ip-insights-input-csv-format"></a>

CSV 檔案必須擁有兩個欄。第一欄是一個不透明字串，對應到實體的唯一識別符。第二欄則是實體地址事件的 IPv4 地址，以小數點表示法表示。

content-type：text/csv

```
entity_id_1, 192.168.1.2
entity_id_2, 10.10.1.2
```

### 輸入：JSON 格式
<a name="ip-insights-input-json"></a>

JSON 資料可以不同的格式提供。IP Insights 遵循常見的 SageMaker AI 格式。如需推論格式的詳細資訊，請參閱[推論的一般資料格式](cdf-inference.md)。

content-type：application/json

```
{
  "instances": [
    {"data": {"features": {"values": ["entity_id_1", "192.168.1.2"]}}},
    {"features": ["entity_id_2", "10.10.1.2"]}
  ]
}
```

### 輸入：JSONLINES 格式
<a name="ip-insights-input-jsonlines"></a>

JSON Lines 內容類型在執行批次轉換任務時很有用。如需 SageMaker AI 推論格式的詳細資訊，請參閱[推論的一般資料格式](cdf-inference.md)。如需執行批次轉換任務的詳細資訊，請參閱[使用 Amazon SageMaker AI 進行批次轉換以進行推論](batch-transform.md)。

content-type：application/jsonlines

```
{"data": {"features": {"values": ["entity_id_1", "192.168.1.2"]}}},
{"features": ["entity_id_2", "10.10.1.2"]}]
```

## IP Insights 輸出回應格式
<a name="ip-insights-ouput-format-response"></a>

### 輸出：JSON 回應格式
<a name="ip-insights-output-json"></a>

SageMaker AI IP Insights 演算法的預設輸出是介於輸入實體和 IP 地址之間的 `dot_product`。dot\$1product 表示模型考慮實體和 IP 地址的相容程度為何。`dot_product` 沒有限制。若要針對事件是否異常進行預測，您需要根據您定義的分布設定閾值。如需如何針對異常偵測使用 `dot_product` 的資訊，請參閱 [SageMaker AIIP Insights 演算法簡介](https://sagemaker-examples.readthedocs.io/en/latest/introduction_to_amazon_algorithms/ipinsights_login/ipinsights-tutorial.html)。

accept：application/json

```
{
  "predictions": [
    {"dot_product": 0.0},
    {"dot_product": 2.0}
  ]
}
```

進階使用者可以透過提供額外的 content-type 參數 `verbose=True` 給 Accept 標頭，來存取模型已學習的實體和 IP 內嵌。您可以使用 `entity_embedding` 和 `ip_embedding` 進行除錯、視覺化和了解模型。此外，您可以在其他機器學習技術 (例如分類或叢集) 中使用這些內嵌。

accept：application/json;verbose=True

```
{
  "predictions": [
    {
        "dot_product": 0.0,
        "entity_embedding": [1.0, 0.0, 0.0],
        "ip_embedding": [0.0, 1.0, 0.0]
    },
    {
        "dot_product": 2.0,
        "entity_embedding": [1.0, 0.0, 1.0],
        "ip_embedding": [1.0, 0.0, 1.0]
    }
  ]
}
```

### 輸出：JSONLINES 回應格式
<a name="ip-insights-jsonlines"></a>

accept：application/jsonlines 

```
{"dot_product": 0.0}
{"dot_product": 2.0}
```

accept：application/jsonlines; verbose=True 

```
{"dot_product": 0.0, "entity_embedding": [1.0, 0.0, 0.0], "ip_embedding": [0.0, 1.0, 0.0]}
{"dot_product": 2.0, "entity_embedding": [1.0, 0.0, 1.0], "ip_embedding": [1.0, 0.0, 1.0]}
```