

# ML Detect
<a name="dd-detect-ml"></a>

**注意**  
ML Detect 在以下区域中不可用：  
亚太地区（马来西亚）

通过机器学习 Detect (ML Detect)，您可以创建安全配置文件，使用机器学习通过基于历史设备数据自动创建模型来学习预期的设备行为，并将这些配置文件分配给一组设备或您机群中的所有设备。AWS IoT Device Defender 然后会使用 ML 模型识别异常并触发告警。

有关 ML Detect 入门的信息，请参阅 [ML Detect 指南](dd-detect-ml-getting-started.md)。

**Topics**
+ [

## ML Detect 的使用案例
](#dd-detect-ml-use-cases)
+ [

## ML Detect 的工作原理
](#dd-detect-ml-how-it-works)
+ [

## 最低要求
](#dd-detect-ml-requirements)
+ [

## 限制
](#dd-detect-ml-limitations)
+ [

## 在告警中标记误报和其它验证状态
](#dd-detect-ml-mark-false-positives)
+ [

## 受支持的指标
](#dd-detect-ml-metrics)
+ [

## 服务配额
](#dd-detect-ml-quotas)
+ [

## ML Detect CLI 命令
](#dd-detect-ml-cli-commands)
+ [

## ML Detect API
](#dd-detect-ml-apis)
+ [

## 暂停或删除 ML Detect 安全配置文件
](#dd-detect-ml-disable-feature)

## ML Detect 的使用案例
<a name="dd-detect-ml-use-cases"></a>

当难以设置设备的预期行为时，您可以使用 ML Detect 来监控您的实例集设备。例如，要监控断开连接数量指标，可能不清楚什么是可接受的阈值。在这种情况下，您可以启用 ML Detect 功能，根据设备报告的历史数据来识别异常断开连接指标数据点。

ML Detect 的另一个使用案例是监控随着时间的推移动态变化的设备行为。ML Detect 根据设备中不断变更的数据模式，定期了解动态预期的设备行为。例如，发送的设备消息量在工作日和周末之间可能会有所不同，而 ML Detect 将了解此动态行为。

## ML Detect 的工作原理
<a name="dd-detect-ml-how-it-works"></a>

使用 ML Detect 功能，您可以创建行为以跨 [6 个云端指标](#dd-detect-ml-metrics)和 [7 个设备端指标](#dd-detect-ml-metrics)识别运营和安全异常。在初始模型训练期之后，ML Detect 会根据最后 14 天的数据每天刷新模型。它使用 ML 模型监控这些指标的数据点，并在检测到异常时触发告警。

如果将安全配置文件附加到具有类似预期行为的设备集合，则 ML Detect 将发挥出最大的作用。例如，如果您的某些设备在客户家中使用，而其他设备在企业办公室中使用，则这两个组之间的设备行为模式可能会有很大差异。您可以将设备组织到*家用设备*事物组和*办公设备*事物组。为了获得最佳异常检测效果，请将每个事物组附加到单独的 ML Detect 安全配置文件。

虽然 ML Detect 将构建初始模型，但在随后的 14 天期间内，每个指标需要 14 天和至少 25000 个数据点才能生成模型。之后，它每天都会更新模型，达到最少数量的指标数据点。如果未满足最低要求，ML Detect 会在第二天尝试构建模型，并在接下来的 30 天内每天重试，然后停止模型以进行评估。

## 最低要求
<a name="dd-detect-ml-requirements"></a>

对于训练和创建初始 ML 模型，ML Detect 具有以下最低要求。

**最低训练时间**  
构建初始模型需要 14 天的时间。之后，模型每天都会使用 14 天后续周期的指标数据进行刷新。

**最低总数据点**  
在过去 14 天内，构建 ML 模型所需的最低数据点为每个指标 25000 个数据点。对于模型的持续训练和刷新，ML Detect 要求受监控设备满足最少的数据点。它大致相当于以下设置：  
+ 60 台设备连接并在 AWS IoT 上每隔 45 分钟执行一次活动。
+ 40 台设备则每隔 30 分钟一次。
+ 15 台设备则每隔 10 分钟一次。
+ 7 台设备则每隔 5 分钟一次。

**设备组目标**  
为收集数据，您必须在安全配置文件的目标事物组中包含事物。

创建初始模型后，ML 模型每天刷新，并在 14 天的后续周期内至少需要 25000 个数据点。

## 限制
<a name="dd-detect-ml-limitations"></a>

您可以将 ML Detect 与有关以下云端指标的维度一起使用：
+ [授权失败 (aws:num-authorization-failures)](detect-cloud-side-metrics.md#detect-auth-failures)
+ [已收到的消息 (aws:num-messages-received)](detect-cloud-side-metrics.md#detect-messages-received)
+ [已发送的消息 (aws:num-messages-sent)](detect-cloud-side-metrics.md#detect-messages-sent)
+ [消息大小 (aws:message-byte-size)](detect-cloud-side-metrics.md#detect-message-size)

ML Detect 不支持以下指标。

**ML Detect 不支持的云端指标：**
+ [源 IP (aws:source-ip-address)](detect-cloud-side-metrics.md#detect-ip-address)

**ML Detect 不支持的设备端指标：**
+ [目标 IP (`aws:destination-ip-addresses`)](detect-device-side-metrics.md#detect-destination-ip-addresses)
+ [侦听 TCP 端口 (`aws:listening-tcp-ports`)](detect-device-side-metrics.md#detect-listening-tcp-ports)
+ [侦听 UDP 端口 (`aws:listening-udp-ports`)](detect-device-side-metrics.md#detect-listening-udp-ports)

自定义指标仅支持 **number**（数值）类型。

## 在告警中标记误报和其它验证状态
<a name="dd-detect-ml-mark-false-positives"></a>

 如果您通过调查验证 ML 检测告警是否为误报，可以将告警的验证状态设置为误报。这可以帮助您和您的团队识别不必回应的告警。您还可以将告警标记为 “真”、“良性”或“未知”。

您可以通过 [AWS IoT Device Defender 控制台](https://docs.aws.amazon.com//iot/latest/developerguide/detect-HowToHowTo.html)或者使用 [PutVerificationStateOnViolation](https://docs.aws.amazon.com/iot/latest/apireference/API_PutVerificationStateOnViolation.html) API 操作。

## 受支持的指标
<a name="dd-detect-ml-metrics"></a>

您可以将以下云端指标与 ML Detect 结合使用：
+ [授权失败 (aws:num-authorization-failures)](detect-cloud-side-metrics.md#detect-auth-failures)
+ [连接尝试 (aws:num-connection-attempts)](detect-cloud-side-metrics.md#detect-num-connection-attempts)
+ [断开连接 (aws:num-disconnects)](detect-cloud-side-metrics.md#detect-num-disconnects)
+ [消息大小 (aws:message-byte-size)](detect-cloud-side-metrics.md#detect-message-size)
+ [已发送的消息 (aws:num-messages-sent)](detect-cloud-side-metrics.md#detect-messages-sent)
+ [已收到的消息 (aws:num-messages-received)](detect-cloud-side-metrics.md#detect-messages-received)

您可以将以下设备端指标与 ML Detect 结合使用：
+ [输出字节数 (`aws:all-bytes-out`)](detect-device-side-metrics.md#detect-all-bytes-out)
+ [字节数 (`aws:all-bytes-in`)](detect-device-side-metrics.md#detect-all-bytes-in)
+ [侦听 TCP 端口计数 (`aws:num-listening-tcp-ports`)](detect-device-side-metrics.md#detect-num-listening-tcp-ports)
+ [侦听 UDP 端口计数 (`aws:num-listening-udp-ports`)](detect-device-side-metrics.md#detect-num-listening-udp-ports)
+ [输出数据包数 (`aws:all-packets-out`)](detect-device-side-metrics.md#detect-all-packets-out)
+ [数据包数 (`aws:all-packets-in`)](detect-device-side-metrics.md#detect-all-packets-in)
+ [已建立的 TCP 连接计数 (`aws:num-established-tcp-connections`)](detect-device-side-metrics.md#detect-num-established-tcp-connections)

## 服务配额
<a name="dd-detect-ml-quotas"></a>

有关 ML Detect 服务配额和限制的信息，请参阅 [AWS IoT Device Defender 端点和配额](https://docs.aws.amazon.com/general/latest/gr/iot_device_defender.html)。

## ML Detect CLI 命令
<a name="dd-detect-ml-cli-commands"></a>

您可以使用以下 CLI 命令来创建和管理 ML Detect。
+ [create-security-profile](https://docs.aws.amazon.com/cli/latest/reference/iot/create-security-profile.html)
+ [attach-security-profile](https://docs.aws.amazon.com/cli/latest/reference/iot/attach-security-profile.html)
+ [list-security-profiles](https://docs.aws.amazon.com/cli/latest/reference/iot/list-security-profiles.html)
+ [describe-security-profile](https://docs.aws.amazon.com/cli/latest/reference/iot/describe-security-profile.html)
+ [update-security-profile](https://docs.aws.amazon.com/cli/latest/reference/iot/update-security-profile.html)
+ [delete-security-profile](https://docs.aws.amazon.com/cli/latest/reference/iot/delete-security-profile.html)
+ [get-behavior-model-training-summaries](https://docs.aws.amazon.com/cli/latest/reference/iot/get-behavior-model-training-summaries.html)
+ [list-active-violations](https://docs.aws.amazon.com/cli/latest/reference/iot/list-active-violations.html)
+ [list-violation-events](https://docs.aws.amazon.com/cli/latest/reference/iot/list-violation-events.html)

## ML Detect API
<a name="dd-detect-ml-apis"></a>

以下 API 可用于创建和管理 ML Detect 安全配置文件。
+ [CreateSecurityProfile](https://docs.aws.amazon.com/iot/latest/apireference/API_CreateSecurityProfile.html)
+ [AttachSecurityProfile](https://docs.aws.amazon.com/iot/latest/apireference/API_AttachSecurityProfile.html)
+ [ListSecurityProfiles](https://docs.aws.amazon.com/iot/latest/apireference/API_ListSecurityProfiles.html)
+ [DescribeSecurityProfile](https://docs.aws.amazon.com/iot/latest/apireference/API_DescribeSecurityProfile.html)
+ [UpdateSecurityProfile](https://docs.aws.amazon.com/iot/latest/apireference/API_UpdateSecurityProfile.html)
+ [DeleteSecurityProfile](https://docs.aws.amazon.com/iot/latest/apireference/API_DeleteSecurityProfile.html)
+ [GetBehaviorModelTrainingSummaries](https://docs.aws.amazon.com/iot/latest/apireference/API_GetBehaviorModelTrainingSummaries.html)
+ [ListActiveViolations](https://docs.aws.amazon.com/iot/latest/apireference/API_ListActiveViolations.html)
+ [ListViolationEvents](https://docs.aws.amazon.com/iot/latest/apireference/API_ListViolationEvents.html)
+ [PutVerificationStateOnViolation](https://docs.aws.amazon.com/iot/latest/apireference/API_PutVerificationStateOnViolation.html)

## 暂停或删除 ML Detect 安全配置文件
<a name="dd-detect-ml-disable-feature"></a>

您可以暂停 ML Detect 安全配置文件以暂时停止监控设备行为，也可以删除 ML Detect 安全配置文件以长时间停止监控设备行为。

**使用控制台暂停 ML Detect 安全配置文件**  
要使用控制台暂停 ML Detect 安全配置文件，您必须首先有一个空的事物组。要创建空的事物组，请参阅《AWS IoT Core 开发人员指南》**中的[静态事物组](https://docs.aws.amazon.com/iot/latest/developerguide/thing-groups.html)。如果已创建空事物组，则将空事物组设置为 ML Detect 安全配置文件的目标。  
 您需要在 30 天内将安全配置文件的目标设置回具有设备的设备组，否则您将无法重新激活安全配置文件。

**使用控制台删除 ML Detect 安全配置文件**  

若要删除安全配置文件，请按照下列步骤操作：

1.  在 AWS IoT 控制台导航到边栏，然后选择 **Defend**（防护）部分。

1. 在 **Defend**（防护）中，选择 **Detect**（检测）然后选择 **Security Profiles**（安全配置文件）。

1. 选择要删除的 ML Detect 安全配置文件。

1. 选择 **Actions**（操作），然后从选项中选择 **Delete**（删除）。
删除 ML Detect 安全配置文件后，您将无法重新激活安全配置文件。

**使用 CLI 暂停 ML Detect 安全配置文件**  
要使用 CLI 暂停 ML Detect 安全配置文件，请使用 `detach-security-security-profile` 命令：  

```
$aws iot detach-security-profile --security-profile-name SecurityProfileName --security-profile-target-arn arn:aws:iot:us-east-1:123456789012:all/registered-things
```
此选项只在 AWS CLI 中可用。与控制台工作流程类似，您需要在 30 天内将安全配置文件的目标设置回具有设备的设备组，否则您将无法重新激活安全配置文件。要将安全配置文件附加到设备组，请使用 [https://docs.aws.amazon.com/cli/latest/reference/iot/attach-security-profile.html](https://docs.aws.amazon.com/cli/latest/reference/iot/attach-security-profile.html) 命令。

**使用 CLI 删除 ML Detect 安全配置文件**  
您可以通过使用如下 `delete-security-profile` 命令删除安全配置文件：  

```
delete-security-profile --security-profile-name SecurityProfileName
```
删除 ML Detect 安全配置文件后，您将无法重新激活安全配置文件。