

我們不再更新 Amazon Machine Learning 服務或接受新使用者。本文件可供現有使用者使用，但我們不再更新。如需詳細資訊，請參閱[什麼是 Amazon Machine Learning](https://docs.aws.amazon.com/machine-learning/latest/dg/what-is-amazon-machine-learning.html)。

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

# 教學課程：使用 Amazon ML 預測對行銷優惠的回應
<a name="tutorial"></a>

透過 Amazon Machine Learning (Amazon ML)，您可以建置和訓練預測模型，並將應用程式託管在可擴展的雲端解決方案中。在本教學課程中，我們會示範如何使用 Amazon ML 主控台來建立資料來源、建置機器學習 (ML) 模型，以及使用該模型來產生您可以在應用程式中使用的預測。

我們的練習範例會說明如何找出目標行銷活動的潛在客戶，但您可以套用該相同原則，來建立及使用各種 ML 模型。為了完成範例練習，您將使用 [University of California at Irvine (UCI) Machine Learning Repository](http://archive.ics.uci.edu/ml/datasets.php) 公開提供的銀行和行銷資料集。這些資料集包含客戶的一般資訊，以及其之前對行銷聯絡人的回應。您將使用此資料找出哪些客戶最可能訂閱您的新產品：銀行定期存款，也稱為定期存單 (CD)。

**警告**  
AWS 免費方案不包含此教學課程。如需 Amazon ML 定價的詳細資訊，請參閱 [https://aws.amazon.com/machine-learning/pricing/](https://aws.amazon.com/machine-learning/pricing/)。

## 先決條件
<a name="prereqs"></a>

 若要執行教學課程，您需要具備 AWS 帳戶。如果您還沒有 AWS 帳戶，請參閱[設定 Amazon Machine Learning](https://docs.aws.amazon.com/machine-learning/latest/dg/setting-up-amazon-machine-learning.html)。

## 步驟
<a name="steps"></a>
+ [步驟 1：準備資料](step-1-download-edit-and-upload-data.md)
+ [步驟 2：建立訓練資料來源](step-2-create-a-datasource.md)
+ [步驟 3：建立 ML 模型](step-3-create-an-ml-model.md)
+ [步驟 4：檢閱 ML 模型的預測效能並設定分數閾值](step-4-review-model-and-set-cutoff.md)
+ [步驟 5：使用 ML 模型產生預測](step-5-create-predictions.md)
+ [步驟 6：清除](step-6-clean-up.md)

# 步驟 1：準備資料
<a name="step-1-download-edit-and-upload-data"></a>

在機器學習中，您通常會取得資料，並先確保它的格式良好，再啟動培訓程序。基於本教學的目的，我們從 [UCI Machine Learning Repository](http://archive.ics.uci.edu/ml/) 取得範例資料集，格式化為符合 Amazon ML 準則，並供您下載。從 Amazon Simple Storage Service (Amazon S3) 儲存位置下載資料集，並遵循本主題中的程序將其上傳至您自己的 S3 儲存貯體。

 如需 Amazon ML 格式要求，請參閱 [了解 Amazon ML 的資料格式](understanding-the-data-format-for-amazon-ml.md)。

**下載資料集**

1. 按一下 [banking.zip](samples/banking.zip)，下載包含已購買類似銀行定期存款產品之客戶歷史資料的檔案。解壓縮資料夾，並將 banking.csv 檔案儲存到您的電腦。

1. 按一下 [banking-batch.zip](samples/banking-batch.zip)，下載您將用來預測潛在客戶是否會回應您的報價的檔案。解壓縮資料夾，並將 banking-batch.csv 檔案儲存到您的電腦。

1.  打開 `banking.csv`。您將會看到資料的資料列和資料行。*「標題列」*包含每個資料行的屬性名稱。*「屬性」*(Attribute) 是唯一具名屬性 (Property)，說明每個客戶的特定特性，例如，nr\$1employed 指出客戶的雇用狀態。每個資料列都代表單一客戶的觀察集合。  
![\[Spreadsheet preview showing header row with columns for euribor3m, nr_employed, and y.\]](http://docs.aws.amazon.com/zh_tw/machine-learning/latest/dg/images/image1.png)

   您希望 ML 模型回答「這位客戶將訂閱我的新產品嗎？」問題。在 `banking.csv` 資料集內，這個問題的答案是 **y** 屬性，其包含值 1 (表示「是」) 或 0 (表示「否」)。您希望 Amazon ML 了解如何預測的屬性稱為*目標屬性*。
**注意**  
屬性 **y** 是二元屬性。它可以只包含兩個值的其中一個值，在這種情況下為 0 或 1。在原始 UCI 資料集內，**y** 屬性為「是」或「否」。我們已為您編輯妥原始資料集。屬性 **y** 表示「是」的所有值現在是 1，而表示「否」的所有值現在是 0。如果您使用自己的資料，則可以使用其他二元屬性值。如需有效值的詳細資訊，請參閱[使用 AttributeType 欄位](creating-a-data-schema-for-amazon-ml.md#assigning-data-types)。

 以下範例顯示將 **y** 屬性的值變更為二元屬性 0 和 1 前後的資料。

![\[Data table showing 'banking.csv' with columns for 'euribor3m', 'nr_employed', and binary 'y' values.\]](http://docs.aws.amazon.com/zh_tw/machine-learning/latest/dg/images/image2.png)


![\[Partial view of a CSV file showing banking data with columns for euribor3m, nr_employed, and y.\]](http://docs.aws.amazon.com/zh_tw/machine-learning/latest/dg/images/image3.png)


 `banking-batch.csv` 檔案未包含 **y** 屬性。在您建立 ML 模型之後，將會使用此模型來預測該檔案中每筆記錄的 **y**。

 接著，將 `banking.csv `和 `banking-batch.csv` 檔案上傳至 Amazon S3。

**將檔案上傳至 Amazon S3 位置**

1. 登入AWS 管理主控台，並在 [https://console.aws.amazon.com/s3/](https://console.aws.amazon.com/s3/)：// 開啟 Amazon S3 主控台。

1.  在 **All Buckets (所有儲存貯體)** 清單中，建立儲存貯體或選擇您要上傳檔案的位置。

1. 在導覽列中，選擇 **Upload (上傳)**。

1. 選擇 **Add Files (新增檔案)**。

1.  在對話方塊中，導覽至您的桌面並選擇 `banking.csv` 和 `banking-batch.csv`，然後選擇 **Open (開啟)**。

 您現在已準備好可[建立培訓資料來源](step-2-create-a-datasource.md)。

# 步驟 2：建立訓練資料來源
<a name="step-2-create-a-datasource"></a>

將`banking.csv`資料集上傳到 Amazon Simple Storage Service (Amazon S3) 位置後，您可以使用它來建立訓練資料來源。資料來源是 Amazon Machine Learning (Amazon ML) 物件，其中包含輸入資料的位置和輸入資料的重要中繼資料。Amazon ML 會將資料來源用於 ML 模型訓練和評估等操作。

若要建立資料來源，請提供下列項目：
+  資料的 Amazon S3 位置和存取資料的許可 
+  結構描述，包含資料中的屬性名稱及各屬性的類型 (數字、文字、分類或二元) 
+  屬性的名稱，其中包含您希望 Amazon ML 學習預測的答案，即目標屬性 

**注意**  
資料來源並不會實際地存放您的資料，只是參考該資料而已。避免移動或變更存放在 Amazon S3 中的檔案。如果您確實移動或變更它們，Amazon ML 無法存取它們來建立 ML 模型、產生評估或產生預測。

**建立訓練資料來源**

1. 開啟位於 https：//[https://console.aws.amazon.com/machinelearning/](https://console.aws.amazon.com/machinelearning/) 的 Amazon Machine Learning 主控台。

1.  選擇**開始使用**。
**注意**  
本教學假設這是您第一次使用 Amazon ML。如果您之前已使用 Amazon ML，則可以使用 Amazon ML 儀表板上的**建立新的...**下拉式清單來建立新的資料來源。

1. 在**開始使用 Amazon Machine Learning** 頁面上，選擇**啟動**。  
![\[Amazon Machine Learning interface with "Launch" button highlighted for standard setup.\]](http://docs.aws.amazon.com/zh_tw/machine-learning/latest/dg/images/get-started-launch.png)

1. 在 **Input Data (輸入資料)** 頁面上，確定 **Where is your data located? (您的資料在哪個位置？)** 已選取 **S3**。  
![\[Radio button selection between S3 and Redshift options, with S3 selected.\]](http://docs.aws.amazon.com/zh_tw/machine-learning/latest/dg/images/image5.png)

1. 為 **S3 Location (S3 位置)** 輸入「步驟 1：準備資料」中 `banking.csv ` 檔案的完整位置。例如：*your-bucket***/banking.csv**。Amazon ML 會在儲存貯體名稱前面加上 s3：//。

1. 針對 **Datasource name (資料來源名稱)**​ 輸入 **Banking Data 1**。  
![\[S3 location input field and Datasource name field for entering banking data information.\]](http://docs.aws.amazon.com/zh_tw/machine-learning/latest/dg/images/image6.png)

1. 選擇 **Verify (驗證)**。

1. 在 **S3 permissions (S3 許可)** 對話方塊中，選擇 **Yes (是)**。  
![\[Dialog box asking to grant Amazon Machine Learning read permission for S3 location.\]](http://docs.aws.amazon.com/zh_tw/machine-learning/latest/dg/images/image7.png)

1.  如果 Amazon ML 可以存取和讀取 S3 位置的資料檔案，您會看到類似以下的頁面。檢閱屬性，然後選擇 **Continue (繼續)**。  
![\[Validation success message with datasource details including name, location, and file information.\]](http://docs.aws.amazon.com/zh_tw/machine-learning/latest/dg/images/image8.png)

接著，您要建立結構描述。*結構描述*是 Amazon ML 解譯 ML 模型輸入資料所需的資訊，包括屬性名稱及其指派的資料類型，以及特殊屬性的名稱。提供 Amazon ML 結構描述的方式有兩種：
+  當您上傳 Amazon S3 資料時，請提供個別的結構描述檔案。
+  允許 Amazon ML 推斷屬性類型並為您建立結構描述。

在本教學課程中，我們會要求 Amazon ML 推斷結構描述。

如需建立獨立結構描述檔案的相關資訊，請參閱[建立 Amazon ML 的資料結構描述](creating-a-data-schema-for-amazon-ml.md)。

**允許 Amazon ML 推斷結構描述**

1. 在**結構描述**頁面上，Amazon ML 會顯示它推斷的結構描述。檢閱 Amazon ML 針對屬性推斷的資料類型。務必為屬性指派正確的資料類型，以協助 Amazon ML 正確擷取資料，並在屬性上啟用正確的特徵處理。
   + 若屬性只有兩種可能狀態 (例如，是或否)，應標示為 **Binary (二元)**。
   + 若屬性為用來表示分類的數字或字串，應標示為 **Categorical (分類)**。
   + 若屬性為順序有意義的數字量，應標示為 **Numeric (數值)**。
   + 若屬性為您想要視為以空格分隔之單詞的字串，應標示為 **Text (文字)**。  
![\[Data table showing fields like age, campaign, and contact with their data types and sample values.\]](http://docs.aws.amazon.com/zh_tw/machine-learning/latest/dg/images/image10.png)

1. 在本教學課程中，Amazon ML 已正確識別所有屬性的資料類型，因此請選擇**繼續**。

接著選取目標屬性。

請記住，目標是 ML 模型必須學習預測的屬性。屬性 **y** 會指出某人過去是否訂閱過活動：1 (是) 或 0 (否)。

**注意**  
只有當您要使用資料來源來訓練和評估 ML 模型時，才選擇目標屬性。

**選取 y 做為目標屬性**

1. 在表格右下方，選擇單箭頭前往表格的最後一頁，該頁會顯示名為 `y` 的屬性。  
![\[Navigation buttons for a paginated table, with the last page arrow highlighted.\]](http://docs.aws.amazon.com/zh_tw/machine-learning/latest/dg/images/image11.png)

1. 在 **Target (目標)** 欄，選取 `y`。  
![\[Checkbox in Target column next to variable 'y' with Binary data type.\]](http://docs.aws.amazon.com/zh_tw/machine-learning/latest/dg/images/image12.png)

   Amazon ML 會確認已選取 **y** 做為您的目標。

1. 選擇**繼續**。

1. 在 **Row ID (列 ID)** 頁面上，確定 **Does your data contain an identifier? (您的資料包含識別符嗎？)** 已選取預設值 **No (否)**。

1. 選擇 **Review (檢閱)**，然後選擇 **Continue (繼續)**。

既然您已具有訓練資料來源，就可以[建立模型](step-3-create-an-ml-model.md)。

# 步驟 3：建立 ML 模型
<a name="step-3-create-an-ml-model"></a>

 建立好訓練資料來源後，可以使用它來建立 ML 模型、訓練模型，然後評估結果。ML 模型是 Amazon ML 在訓練期間在您的資料中找到的模式集合。您可以使用模型來建立預測。

**建立 ML 模型**

1.  由於入門精靈同時建立訓練資料來源和模型，Amazon Machine Learning (Amazon ML) 會自動使用您剛建立的訓練資料來源，並直接帶您前往 **ML 模型設定**頁面。在 **ML model settings (ML 模型設定)** 頁面上，確定 **ML model name (ML 模型名稱)** 已顯示預設選項 **ML model: Banking Data 1**。

   使用好記的名稱 (例如預設值)，可協助您輕鬆地識別和管理 ML 模型。

1.  對於 **Training and evaluation settings (訓練與評估設定)**，確定已選取 **Default (預設)**。  
![\[Select training and evaluation settings interface with Default option selected.\]](http://docs.aws.amazon.com/zh_tw/machine-learning/latest/dg/images/image19.png)

1.  對於 **Name this evaluation (命名此評估)**，接受預設值 **Evaluation: ML model: Banking Data 1**。

1.  選擇 **Review (檢閱)**、檢閱您的設定，然後選擇 **Finish (完成)**。

    選擇**完成**之後，Amazon ML 會將模型新增至處理佇列。Amazon ML 建立模型時，會套用預設值並執行下列動作：
   + 將訓練資料來源分割為兩個部分，其一包含 70% 的資料，另一部分包含其餘的 30% 
   + 使用包含 70% 輸入資料的部分來訓練 ML 模型 
   + 使用其餘 30% 輸入資料的部分來評估模型 

   當您的模型在佇列中時，Amazon ML 會將狀態報告為**待定**。Amazon ML 建立模型時，會將狀態報告為**進行中**。待已完成所有動作後，則回報狀態為 **Completed (已完成)**。請等待評估完成，然後再繼續。

現在您已準備好要開始[檢閱模型的效能和設定分界分數](step-4-review-model-and-set-cutoff.md)。

 如需訓練和評估模型的詳細資訊，請參閱[定型 ML 模型](training-ml-models.md)和[評估 ML 模型](evaluating_models.md)。

# 步驟 4：檢閱 ML 模型的預測效能並設定分數閾值
<a name="step-4-review-model-and-set-cutoff"></a>

 現在您已建立 ML 模型，且 Amazon Machine Learning (Amazon ML) 已對其進行評估，讓我們來看看它是否足夠使用。在評估期間，Amazon ML 計算了一個產業標準品質指標，稱為曲線下面積 (AUC) 指標，可表達 ML 模型的效能品質。Amazon ML 也會解譯 AUC 指標，以告訴您 ML 模型的品質是否適用於大多數機器學習應用程式。(請至[衡量 ML 模型準確性](binary-model-insights.md#measuring-ml-model-accuracy)進一步了解 AUC)。讓我們檢閱 AUC 指標，然後調整分數閾值或分界值以最佳化模型的預測效能。

**檢閱 ML 模型的 AUC 指標**

1.  在 **ML model summary (ML 模型摘要)** 頁面的 **ML model report (ML 模型報告)** 導覽窗格中，選擇 **Evaluations (評估)**、選擇 **Evaluation: ML model: Banking model 1 (評估：ML 模型：Banking model 1)**，然後選擇 **Summary (摘要)**。

1.  在 **Evaluation summary (評估摘要)** 頁面上，檢閱評估摘要，包括模型的 AUC 效能指標。  
![\[ML model performance metric showing extremely good quality score with AUC of 0.94.\]](http://docs.aws.amazon.com/zh_tw/machine-learning/latest/dg/images/image24.png)

 ML 模型會為預測資料來源中的每個記錄各產生數值預測分數，然後套用閾值以將這些分數轉換為 0 (否) 或 1 (是) 的二元標籤。透過變更 *score threshold (分數閾值)*，您可以調整 ML 模型指派這些標籤的方式。現在，設定分數閾值。

 **為 ML 模型設定分數閾值** 

1.  在 **Evaluation Summary (評估摘要)** 頁面上，選擇 **Adjust Score Threshold (調整分數閾值)**。  
![\[ML model performance chart showing predicted distributions for "1" and "0" records with adjustable score threshold.\]](http://docs.aws.amazon.com/zh_tw/machine-learning/latest/dg/images/image25.png)

   您可以透過調整分數閾值來微調 ML 模型的效能指標。調整這個值會改變模型在預測中必須具備的可信度等級，用以將某個預測視為陽性。也會改變您願意在預測中容忍多少偽陽性和偽陰性結果。

    您可以透過增加分數閾值來控制模型會將哪些考慮為陽性預測的分界值，直到模型只將具有最高真陽性可能性的預測看作是陽性的。您也可以降低分數閾值，直到您不再有任何偽陽性。選擇您的分界值，以反映您的業務需求。在本教學課程中，每個偽陽性都會花費行銷活動資金，所以我們希望真陽性的比例高於偽陽性。

1. 舉例來說，您想要鎖定會訂閱產品的前 3% 客戶。滑動垂直選取器，將分數閾值設定至對應到 **3% of the records are predicted as "1" (3% 的記錄會預測為「1」)** 的值。  
![\[ML model performance chart showing distribution of predicted answers for "1" and "0" records.\]](http://docs.aws.amazon.com/zh_tw/machine-learning/latest/dg/images/image26.png)

    請注意，此分數閾值對 ML 模型效能的影響：偽陽性率為 0.007。假設此偽陽性率是可接受的值。

1.  選擇 **Save score threshold at 0.77 (將分數閾值儲存在 0.77)**。

每當您使用此 ML 模型來進行預測，它會將分數超過 0.77 的記錄預測為「1」，其餘記錄預測為「0」。

若要進一步了解分數閾值，請參閱[二元分類](binary-classification.md)。

現在您已準備好要開始[使用您的模型建立預測](step-5-create-predictions.md)。

# 步驟 5：使用 ML 模型產生預測
<a name="step-5-create-predictions"></a>

 Amazon Machine Learning (Amazon ML) 可以產生兩種類型的預測：批次和即時。

*即時預測*是 Amazon ML 隨需產生的單一觀察的預測。即時預測適用於行動應用程式、網站和其他需要以互動方式使用結果的應用程式。

 *批次預測*是一組觀察的一組預測。Amazon ML 會一起處理批次預測中的記錄，因此處理可能需要一些時間。批次預測適用於需要一組觀察的預測或不以互動方式使用結果的預測之應用程式。

在本教學課程中，您會產生即時預測，預測某位潛在客戶是否會訂閱新產品。您也會產生大批次潛在客戶的預測。在批次預測方面，您將會使用您在「`banking-batch.csv`」中上傳的 [步驟 1：準備資料](step-1-download-edit-and-upload-data.md) 檔案。

那麼就先從即時預測開始。

**注意**  
對於需要即時預測的應用程式，您必須建立 ML 模型的即時端點。當即時端點可使用時，會產生費用。在您承諾使用即時預測並開始產生與其相關的費用前，可以先在 Web 瀏覽器中試用即時預測功能，而不用建立即時端點。這就是在本教學課程中將要操作的內容。

**試用即時預測**

1. 在 **ML model report (ML 模型報告)** 導覽窗格中，選擇 **Try real-time predictions (試用即時預測)**。  
![\[Navigation pane with "Try real-time predictions" option circled in red.\]](http://docs.aws.amazon.com/zh_tw/machine-learning/latest/dg/images/try-real-time-prediction-menu.png)

1. 選擇 **Paste a record (貼上記錄)**。  
![\[Button labeled "Paste a record" highlighted in a web interface form.\]](http://docs.aws.amazon.com/zh_tw/machine-learning/latest/dg/images/paste-a-record.png)

1. 在 **Paste a record (貼上記錄)** 對話方塊中，貼上以下觀察：

   ```
   32,services,divorced,basic.9y,no,unknown,yes,cellular,dec,mon,110,1,11,0,nonexistent,-1.8,94.465,-36.1,0.883,5228.1
   ```

1. 在**貼上記錄**對話方塊中，選擇**提交**以確認您想要為此觀察產生預測。Amazon ML 會以即時預測形式填入值。  
![\[Table row showing 'age' attribute with Numeric type and Value of 32.0.\]](http://docs.aws.amazon.com/zh_tw/machine-learning/latest/dg/images/value-column.png)
**注意**  
您也可以輸入個別的值，藉此填入 **Value (值)** 欄位。無論您選擇何種方法，都應提供不是用於訓練模型的觀察。

1. 在頁面底部，選擇 **Create prediction (建立預測)**。

   預測會顯示在右側的 **Prediction results (預測結果)** 窗格中。此預測的 **Predicted label (預測標籤)** 為 `0`，表示此潛在客戶不可能回應活動。**Predicted label (預測標籤)** 為 `1` 則表示客戶可能回應活動。  
![\[Prediction results showing binary ML model with predicted label 0 and score 0.033486433.\]](http://docs.aws.amazon.com/zh_tw/machine-learning/latest/dg/images/real-time-result.png)

現在來建立批次預測。您將向 Amazon ML 提供您正在使用的 ML 模型名稱、您要產生預測之輸入資料的 Amazon Simple Storage Service (Amazon S3) 位置 (Amazon ML 會從此資料建立批次預測資料來源），以及用於儲存結果的 Amazon S3 位置。

**建立批次預測**

1. 選擇 **Amazon Machine Learning**，然後選擇 **Batch Predictions (批次預測)**。  
![\[Amazon Machine Learning dropdown menu with Batch Predictions option highlighted.\]](http://docs.aws.amazon.com/zh_tw/machine-learning/latest/dg/images/image29.png)

1. 選擇 **Create new batch prediction (建立新的批次預測)**。

1. 在 **ML model for batch predictions (批次預測的 ML 模型)** 頁面上，選擇 **ML model: Banking Data 1 (ML 模型：Banking Data 1)**。

   Amazon ML 會顯示 ML 模型名稱、ID、建立時間和相關聯的資料來源 ID。

1. 選擇**繼續**。

1. 若要產生預測，您需要向 Amazon ML 提供您需要預測的資料。這稱為*「輸入資料」*。首先，將輸入資料放入資料來源，以便 Amazon ML 可以存取。

   **Locate the input data (尋找輸入資料)** 選擇 **My data is in S3, and I need to create a datasource (我的資料存放在 S3 中，而且我需要建立資料來源)**。  
![\[Radio button options for locating input data, with the second option selected.\]](http://docs.aws.amazon.com/zh_tw/machine-learning/latest/dg/images/image31.png)

1. 針對 **Datasource name (資料來源名稱)**​ 輸入 **Banking Data 2**。

1. **S3 Location (S3 位置)** 輸入 `banking-batch.csv` 檔案的完整位置：*您的儲存貯體***/banking-batch.csv**。

1. **Does the first line in your CSV contain the column names? (CSV 的第一行是否包含欄名？)** 選擇 **Yes (是)**。

1. 選擇 **Verify (驗證)**。

   Amazon ML 會驗證資料的位置。

1. 選擇**繼續**。

1. 針對 **S3 目的地**，輸入您在步驟 1：準備資料中上傳檔案的 Amazon S3 位置名稱。Amazon ML 會在那裡上傳預測結果。

1. 對於**批次預測名稱**，接受預設值 **Batch prediction: ML model: Banking Data 1**。Amazon ML 會根據用於建立預測的模型來選擇預設名稱。在本教學課程中，模型和預測結果都會以訓練資料來源 `Banking Data 1` 命名。

1. 選擇**檢閱**。

1. 在 **S3 permissions (S3 許可)** 對話方塊中，選擇 **Yes (是)**。  
![\[Dialog box asking to grant Amazon Machine Learning write permission on S3 location.\]](http://docs.aws.amazon.com/zh_tw/machine-learning/latest/dg/images/image32.png)

1. 在 **Review (檢閱)** 頁面上，選擇 **Finish (完成)**。

   批次預測請求會傳送至 Amazon ML 並輸入佇列。Amazon ML 處理批次預測所需的時間取決於資料來源的大小和 ML 模型的複雜性。當 Amazon ML 處理請求時，它會報告**進行中**的狀態。在批次預測完成後，請求的狀態會變更為 **Completed (已完成)**。您現在可以檢視結果。

**檢視預測**

1. 選擇 **Amazon Machine Learning**，然後選擇 **Batch Predictions (批次預測)**。  
![\[Amazon Machine Learning dropdown menu showing options including Batch Predictions.\]](http://docs.aws.amazon.com/zh_tw/machine-learning/latest/dg/images/image33.png)

1. 在預測清單中，選擇 **Batch prediction: ML model: Banking Data 1 (批次預測：ML 模型：Banking Data 1)**。**Batch prediction info (批次預測資訊)** 頁面隨即出現。  
![\[Batch prediction details including name, ID, status, and associated data sources and models.\]](http://docs.aws.amazon.com/zh_tw/machine-learning/latest/dg/images/image34.png)

1. 若要檢視批次預測的結果，請前往 Amazon S3 主控台，網址為 [https://console.aws.amazon.com/s3/](https://console.aws.amazon.com/s3/)：//Amazon S3**S3**。從該位置再導覽至結果資料夾，其名稱類似於 `s3://aml-data/batch-prediction/result`。  
![\[AWS S3 console showing a single file in the batch-prediction result folder.\]](http://docs.aws.amazon.com/zh_tw/machine-learning/latest/dg/images/image35.png)

   預測會存放在壓縮的 .gzip 檔案中，副檔名為 .gz。

1. 將預測檔案下載到您的桌面，解壓縮後開啟它。  
![\[Table showing bestAnswer scores with numerical values ranging from 0.00046 to 0.30811.\]](http://docs.aws.amazon.com/zh_tw/machine-learning/latest/dg/images/image36.png)

   該檔案會有兩欄：**bestAnswer (最佳答案)** 和 **score (分數)**，同時您的資料來源中的每項觀察各占一列。**bestAnswer (最佳答案)** 欄內的結果是以您在[步驟 4：檢閱 ML 模型的預測效能並設定分數閾值](step-4-review-model-and-set-cutoff.md)時設定的分數閾值 0.77 為依據。**score (分數)** 大於 0.77 會得到 **bestAnswer (最佳答案)** 為 1 表示正回應或預測，而 **score (分數)** 小於 0.77 會得到 **bestAnswer (最佳答案)** 為 0 表示負回應或預測。

   下列範例顯示以 0.77 為分數閾值的正負預測。

 正預測：

![\[Table showing bestAnswer score of 1 with a corresponding value of 0.822876.\]](http://docs.aws.amazon.com/zh_tw/machine-learning/latest/dg/images/image37.png)


在此範例中，**bestAnswer (最佳答案)** 的值為 1，而 **score (分數)** 的值為 0.8228876。**bestAnswer (最佳答案)** 的值為 1 是因為 **score (分數)** 大於分數閾值 0.77。**bestAnswer (最佳答案)** 為 1 表示客戶可能會購買您的產品，因而視為正預測。

 負預測：

![\[Table showing bestAnswer score of 0 and a numerical score of 0.7693356.\]](http://docs.aws.amazon.com/zh_tw/machine-learning/latest/dg/images/image38.png)


 在此範例中，**bestAnswer (最佳答案)** 的值為 0 是因為 **score (分數)** 值 0.7695356 小於分數閾值 0.77。**bestAnswer (最佳答案)** 為 0 表示客戶不太可能購買您的產品，因而視為負預測。

批次結果的每列均會對應到您批次輸入中的一列 (您資料來源中的觀察)。

分析了預測結果後，您就可以執行您的目標行銷活動，例如向所有預測分數為 `1` 的人發送傳單。

既然您已建立、檢閱並使用了模型，請[清理您建立的資料和 AWS 資源](step-6-clean-up.md)，以免產生不必要的費用，並保持工作空間整齊。

# 步驟 6：清除
<a name="step-6-clean-up"></a>

若要避免產生額外的 Amazon Simple Storage Service (Amazon S3) 費用，請刪除存放在 Amazon S3 中的資料。您不需要支付其他未使用 Amazon ML 資源的費用，但我們建議您刪除這些資源，以保持工作區的乾淨。<a name="delete-input-data"></a>

**刪除存放在 Amazon S3 中的輸入資料**

1. 開啟位於 [https://console.aws.amazon.com/s3/](https://console.aws.amazon.com/s3/) 的 Amazon S3 主控台。

1.  導覽至您存放 `banking.csv`和 `banking-batch.csv` 檔案的 Amazon S3 位置。

1.  選取 `banking.csv`、`banking-batch.csv` 和 `.writePermissionCheck.tmp` 檔案。

1.  選擇**動作**，然後選擇**刪除**。

1.  出現確認提示時，請選擇 **OK (確定)**。

雖然您不需要付費保留 Amazon ML 執行的批次預測記錄，或是您在教學課程中建立的資料來源、模型和評估記錄，但建議您刪除這些預測，以避免工作區的雜亂。<a name="delete-predictions"></a>

**刪除批次預測**

1.  導覽至您存放批次預測輸出的 Amazon S3 位置。

1.  選擇 `batch-prediction` 資料夾。

1.  選擇**動作**，然後選擇**刪除**。

1.  出現確認提示時，請選擇 **OK (確定)**。<a name="delete-ml-resources"></a>

**刪除 Amazon ML 資源**

1. 在 Amazon ML 儀表板上，選取下列資源。
   + `Banking Data 1` 資料來源
   + `Banking Data 1_[percentBegin=0, percentEnd=70, strategy=sequential]` 資料來源
   + `Banking Data 1_[percentBegin=70, percentEnd=100, strategy=sequential]` 資料來源
   + `Banking Data 2` 資料來源
   + `ML model: Banking Data 1` ML 模型 
   + `Evaluation: ML model: Banking Data 1` 評估

1. 選擇**動作**，然後選擇**刪除**。

1. 在對話方塊中選擇 **Delete (刪除)**，刪除所有選取的資源。

 您現在已成功完成指導教學。若要繼續使用主控台建立資料來源、模型和預測，請參閱 [Amazon Machine Learning 開發人員指南](https://docs.aws.amazon.com/machine-learning/latest/dg/)。若要了解如何使用 API，請參閱《[ Amazon Machine Learning API 參考 ](https://docs.aws.amazon.com/machine-learning/latest/APIReference/)》。