

文件 AWS 開發套件範例 GitHub 儲存庫中有更多可用的 [AWS SDK 範例](https://github.com/awsdocs/aws-doc-sdk-examples)。

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

# 使用 Tools for PowerShell V5 的 Amazon ML 範例
<a name="powershell_5_machine-learning_code_examples"></a>

下列程式碼範例示範如何使用 AWS Tools for PowerShell V5 搭配 Amazon ML 來執行動作和實作常見案例。

*Actions* 是大型程式的程式碼摘錄，必須在內容中執行。雖然動作會告訴您如何呼叫個別服務函數，但您可以在其相關情境中查看內容中的動作。

每個範例均包含完整原始碼的連結，您可在連結中找到如何設定和執行內容中程式碼的相關指示。

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

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

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

以下程式碼範例顯示如何使用 `Get-MLBatchPrediction`。

**Tools for PowerShell V5**  
**範例 1：傳回具有該 ID 的批次預測的詳細中繼資料。**  

```
Get-MLBatchPrediction -BatchPredictionId ID
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [GetBatchPrediction](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-MLBatchPredictionList`。

**Tools for PowerShell V5**  
**範例 1：傳回符合請求中給定搜尋條件的所有 BatchPredictions 及其相關聯資料記錄的清單。**  

```
Get-MLBatchPredictionList
```
**範例 2：傳回狀態為 COMPLETED 的所有 BatchPredictions 的清單。**  

```
Get-MLBatchPredictionList -FilterVariable Status -EQ COMPLETED
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeBatchPredictions](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-MLDataSource`。

**Tools for PowerShell V5**  
**範例 1：傳回 id 為 ID 之 DataSource 的中繼資料、狀態和資料檔案資訊**  

```
Get-MLDataSource -DataSourceId ID
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [GetDataSource](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-MLDataSourceList`。

**Tools for PowerShell V5**  
**範例 1：傳回所有 DataSources 及其相關聯資料記錄的清單。**  

```
Get-MLDataSourceList
```
**範例 2：傳回狀態為 COMPLETED 的所有 DataSources 清單。**  

```
Get-MLDataDourceList -FilterVariable Status -EQ COMPLETED
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeDataSources](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-MLEvaluation`。

**Tools for PowerShell V5**  
**範例 1：傳回具有 ID 之評估的中繼資料和狀態。**  

```
Get-MLEvaluation -EvaluationId ID
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [GetEvaluation](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-MLEvaluationList`。

**Tools for PowerShell V5**  
**範例 1：傳回所有評估資源的清單**  

```
Get-MLEvaluationList
```
**範例 2：傳回狀態為 COMPLETED 的所有評估清單。**  

```
Get-MLEvaluationList -FilterVariable Status -EQ COMPLETED
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeEvaluations](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-MLModel`。

**Tools for PowerShell V5**  
**範例 1：傳回 id 為 ID 之 MLModel 的詳細資訊中繼資料、狀態、結構描述和資料檔案資訊。**  

```
Get-MLModel -ModelId ID
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [GetMLModel](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-MLModelList`。

**Tools for PowerShell V5**  
**範例 1：傳回所有模型及其相關聯資料記錄的清單。**  

```
Get-MLModelList
```
**範例 2：傳回狀態為 COMPLETED 的所有模型清單。**  

```
Get-MLModelList -FilterVariable Status -EQ COMPLETED
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [DescribeMLModels](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `Get-MLPrediction`。

**Tools for PowerShell V5**  
**範例 1：將記錄傳送至 id 為 ID 之模型的即時預測端點 URL。**  

```
Get-MLPrediction -ModelId ID -PredictEndpoint URL -Record @{"A" = "B"; "C" = "D";}
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [Predict](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-MLBatchPrediction`。

**Tools for PowerShell V5**  
**範例 1：為 id 為 ID 之模型建立新的批次預測請求，並將輸出放在指定的 S3 位置。**  

```
New-MLBatchPrediction -ModelId ID -Name NAME -OutputURI s3://...
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [CreateBatchPrediction](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-MLDataSourceFromS3`。

**Tools for 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 參考 (V5)》**中的 [CreateDataSourceFromS3](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-MLEvaluation`。

**Tools for PowerShell V5**  
**範例 1：為給定的資料來源 ID 和模型 ID 建立評估**  

```
New-MLEvaluation -Name NAME -DataSourceId DSID -ModelId MID
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [CreateEvaluation](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-MLModel`。

**Tools for PowerShell V5**  
**範例 1：使用訓練資料建立新模型。**  

```
New-MLModel -Name NAME -ModelType BINARY -Parameter @{...} -TrainingDataSourceId ID
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [CreateMLModel](https://docs.aws.amazon.com/powershell/v5/reference)。

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

以下程式碼範例顯示如何使用 `New-MLRealtimeEndpoint`。

**Tools for PowerShell V5**  
**範例 1：為給定的模型 ID 建立新的即時預測端點。**  

```
New-MLRealtimeEndpoint -ModelId ID
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [CreateRealtimeEndpoint](https://docs.aws.amazon.com/powershell/v5/reference)。