

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

# IP 洞察推理数据格式
<a name="ip-insights-inference-data-formats"></a>

以下是 IP 洞察算法的可用输入和输出格式。Amazon SageMaker AI 内置算法遵循中[用于推理的常见数据格式](cdf-inference.md)描述的通用输入推理格式。但是， SageMaker AI IP Insights 算法目前不支持 Recordio 格式。

## IP 洞察输入请求格式
<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 行内容类型对于运行批量转换作业非常有用。有关 SageMaker AI 推理格式的更多信息，请参阅[用于推理的常见数据格式](cdf-inference.md)。有关运行批量转换作业的更多信息，请参阅[使用 Amazon A SageMaker I 进行批量转换以进行推理](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 洞察输出响应格式
<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` 是无界的。要预测某个事件是否异常，您需要根据定义的分布设置阈值。有关如何使用进行异常检测的信息，请参阅 [ SageMaker AIIP Insights 算法简介](https://sagemaker-examples.readthedocs.io/en/latest/introduction_to_amazon_algorithms/ipinsights_login/ipinsights-tutorial.html)。`dot_product`

accept: application/json

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

高级用户可以通过向 Accept 标题提供额外的 content-type 参数 `verbose=True`，访问模型已经学习的实体和 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>

接受： 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]}
```