

的版本 5 (V5) AWS Tools for PowerShell 已经发布！

有关重大更改和迁移应用程序的信息，请参阅[迁移主题](https://docs.aws.amazon.com/powershell/v5/userguide/migrating-v5.html)。

 [https://docs.aws.amazon.com/powershell/v5/userguide/migrating-v5.html](https://docs.aws.amazon.com/powershell/v5/userguide/migrating-v5.html)

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

# 使用适用于 PowerShell V5 的工具的 Amazon 机器学习示例
<a name="powershell_machine-learning_code_examples"></a>

以下代码示例向您展示如何使用带有 Amazon ML 的 AWS Tools for PowerShell V5 来执行操作和实现常见场景。

*操作*是大型程序的代码摘录，必须在上下文中运行。您可以通过操作了解如何调用单个服务函数，还可以通过函数相关场景的上下文查看操作。

每个示例都包含一个指向完整源代码的链接，您可以从中找到有关如何在上下文中设置和运行代码的说明。

**Topics**
+ [操作](#actions)

## 操作
<a name="actions"></a>

### `Get-MLBatchPrediction`
<a name="machine-learning_GetBatchPrediction_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-MLBatchPrediction`。

**适用于 PowerShell V5 的工具**  
**示例 1：返回 id 为 ID 的批量预测的详细元数据。**  

```
Get-MLBatchPrediction -BatchPredictionId ID
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [GetBatchPrediction](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-MLBatchPredictionList`
<a name="machine-learning_DescribeBatchPredictions_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-MLBatchPredictionList`。

**适用于 PowerShell V5 的工具**  
**示例 1：返回 BatchPredictions 与请求中给出的搜索条件相匹配的所有数据记录及其关联数据记录的列表。**  

```
Get-MLBatchPredictionList
```
**示例 2：返回状态为 “已完成” 的所有 BatchPredictions 内容的列表。**  

```
Get-MLBatchPredictionList -FilterVariable Status -EQ COMPLETED
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeBatchPredictions](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-MLDataSource`
<a name="machine-learning_GetDataSource_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-MLDataSource`。

**适用于 PowerShell V5 的工具**  
**示例 1：返回 ID 为 ID 的 a DataSource 的元数据、状态和数据文件信息**  

```
Get-MLDataSource -DataSourceId ID
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [GetDataSource](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-MLDataSourceList`
<a name="machine-learning_DescribeDataSources_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-MLDataSourceList`。

**适用于 PowerShell V5 的工具**  
**示例 1：返回所有数据记录 DataSources 及其关联数据记录的列表。**  

```
Get-MLDataSourceList
```
**示例 2：返回状态为 “已完成” 的所有 DataSources 内容的列表。**  

```
Get-MLDataDourceList -FilterVariable Status -EQ COMPLETED
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeDataSources](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-MLEvaluation`
<a name="machine-learning_GetEvaluation_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-MLEvaluation`。

**适用于 PowerShell V5 的工具**  
**示例 1：返回 id 为 ID 的 Evaluation 的元数据和状态。**  

```
Get-MLEvaluation -EvaluationId ID
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [GetEvaluation](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-MLEvaluationList`
<a name="machine-learning_DescribeEvaluations_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-MLEvaluationList`。

**适用于 PowerShell V5 的工具**  
**示例 1：返回所有 Evaluation 资源的列表**  

```
Get-MLEvaluationList
```
**示例 2：返回状态为 COMPLETED 的所有 Evaulation 的列表。**  

```
Get-MLEvaluationList -FilterVariable Status -EQ COMPLETED
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [DescribeEvaluations](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `Get-MLModel`
<a name="machine-learning_GetMLModel_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-MLModel`。

**适用于 PowerShell V5 的工具**  
**示例 1：返回 ID 为 ID 的详细元数据、状态、架构和数据文件信息。 MLModel **  

```
Get-MLModel -ModelId ID
```
+  有关 API 的详细信息，请参阅 [Get MLModel in AWS Tools for PowerShell](https://docs.aws.amazon.com/powershell/v5/reference) *Cmdlet 参考 (V5)*。

### `Get-MLModelList`
<a name="machine-learning_DescribeMLModels_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-MLModelList`。

**适用于 PowerShell V5 的工具**  
**示例 1：返回所有 Model 及其关联数据记录的列表。**  

```
Get-MLModelList
```
**示例 2：返回状态为 COMPLETED 的所有 Model 的列表。**  

```
Get-MLModelList -FilterVariable Status -EQ COMPLETED
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考文档 (V* 5) MLModels 中的[描述](https://docs.aws.amazon.com/powershell/v5/reference)。

### `Get-MLPrediction`
<a name="machine-learning_Predict_powershell_topic"></a>

以下代码示例演示了如何使用 `Get-MLPrediction`。

**适用于 PowerShell V5 的工具**  
**示例 1：向 id 为 ID 的模型的实时预测端点 URL 发送一条记录。**  

```
Get-MLPrediction -ModelId ID -PredictEndpoint URL -Record @{"A" = "B"; "C" = "D";}
```
+  有关 API 详细信息，请参阅《AWS Tools for PowerShell Cmdlet Reference (V5)》**中的 [Predict](https://docs.aws.amazon.com/powershell/v5/reference)。

### `New-MLBatchPrediction`
<a name="machine-learning_CreateBatchPrediction_powershell_topic"></a>

以下代码示例演示了如何使用 `New-MLBatchPrediction`。

**适用于 PowerShell V5 的工具**  
**示例 1：为 id 为 ID 的模型创建新的批量预测请求，并将输出放在指定的 S3 位置。**  

```
New-MLBatchPrediction -ModelId ID -Name NAME -OutputURI s3://...
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CreateBatchPrediction](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-MLDataSourceFromS3`
<a name="machine-learning_CreateDataSourceFromS3_powershell_topic"></a>

以下代码示例演示了如何使用 `New-MLDataSourceFromS3`。

**适用于 PowerShell V5 的工具**  
**示例 1：使用 S3 位置的数据创建数据来源，名称为 NAME，架构为 SCHEMA。**  

```
New-MLDataSourceFromS3 -Name NAME -ComputeStatistics $true -DataSpec_DataLocationS3 "s3://BUCKET/KEY" -DataSchema SCHEMA
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CreateDataSourceFrom中的 S3](https://docs.aws.amazon.com/powershell/v5/reference)。

### `New-MLEvaluation`
<a name="machine-learning_CreateEvaluation_powershell_topic"></a>

以下代码示例演示了如何使用 `New-MLEvaluation`。

**适用于 PowerShell V5 的工具**  
**示例 1：为给定的数据来源 ID 和模型 ID 创建评估**  

```
New-MLEvaluation -Name NAME -DataSourceId DSID -ModelId MID
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CreateEvaluation](https://docs.aws.amazon.com/powershell/v5/reference)中的。

### `New-MLModel`
<a name="machine-learning_CreateMLModel_powershell_topic"></a>

以下代码示例演示了如何使用 `New-MLModel`。

**适用于 PowerShell V5 的工具**  
**示例 1：使用训练数据创建新模型。**  

```
New-MLModel -Name NAME -ModelType BINARY -Parameter @{...} -TrainingDataSourceId ID
```
+  有关 API 的详细信息，请参阅MLModel在 *AWS Tools for PowerShell Cmdlet 参考文档 (V* 5) 中[创建](https://docs.aws.amazon.com/powershell/v5/reference)。

### `New-MLRealtimeEndpoint`
<a name="machine-learning_CreateRealtimeEndpoint_powershell_topic"></a>

以下代码示例演示了如何使用 `New-MLRealtimeEndpoint`。

**适用于 PowerShell V5 的工具**  
**示例 1：为给定模型 ID 创建新的实时预测端点。**  

```
New-MLRealtimeEndpoint -ModelId ID
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CreateRealtimeEndpoint](https://docs.aws.amazon.com/powershell/v5/reference)中的。