教學課程:透過視覺化介面部署機器學習模型Tutorial: Deploy a machine learning model with the visual interface

在本教學課程中,您將進一步了解如何在 Azure Machine Learning 服務視覺化介面中開發預測解決方案。In this tutorial, you take an extended look at developing a predictive solution in the Azure Machine Learning service visual interface. 本教學課程是兩部分教學課程系列的第二部分This tutorial is part two of a two-part tutorial series. 教學課程的第一部分中,您已定型、評分及評估模型來預測汽車價格。In part one of the tutorial, you trained, scored, and evaluated a model to predict car prices. 在教學課程的這個部分中,您將:In this part of the tutorial, you:

  • 準備模型進行部署Prepare a model for deployment
  • 部署 Web 服務Deploy a web service
  • 測試 Web 服務Test a web service
  • 管理 Web 服務Manage a web service
  • 取用 Web 服務Consume the web service

必要條件Prerequisites

完成本教學課程的第一部分Complete part one of the tutorial.

準備部署Prepare for deployment

為了讓其他人有機會使用本教學課程中開發的預測模型,您可以將其部署為 Azure Web 服務。To give others a chance to use the predictive model developed in this tutorial, you can deploy it as an Azure web service.

截至目前為止,您一直在試驗如何定型模型。So far, you've been experimenting with training your model. 現在,是時候根據使用者輸入來產生新預測了。Now, it's time to generate new predictions based on user input.

部署準備是包含兩個步驟的程序:Preparation for deployment is a two-step process:

  1. 將您所建立的「訓練實驗」 轉換成「預測實驗」 Convert the training experiment that you've created into a predictive experiment
  2. 將預測實驗部署為 Web 服務Deploy the predictive experiment as a web service

您可能需要選取實驗畫布底部的 [另存新檔] ,先建立一份實驗複本。You may want to make a copy of the experiment first by selecting Save As at the bottom of the experiment canvas.

將訓練實驗轉換為預測實驗Convert the training experiment to a predictive experiment

若要備妥此模型以進行部署,請將此訓練實驗轉換為預測實驗。To get this model ready for deployment, convert this training experiment to a predictive experiment. 這通常包含三個步驟:This typically involves three steps:

  1. 儲存已定型的模型,並取代您的定型模組Save the model you've trained and replace your training modules
  2. 精簡實驗,移除只有定型才需要的模組Trim the experiment to remove modules that were only needed for training
  3. 定義 Web 服務將接受輸入資料的位置和產生輸出的位置Define where the web service will accept input data and where it generates the output

您可以手動執行這些步驟,或是選取實驗畫布底部的 [設定 Web 服務] ,讓其自動完成。You could do these steps manually or you could select Set Up Web Service at the bottom of the experiment canvas to have them done automatically.

示範訓練實驗如何自動轉換為預測實驗的 gif 動畫

當您選取 [設定 Web 服務] 時,會發生幾件事:When you select Set Up Web Service, several things happen:

  • 定型模型會轉換成單一的定型模型模組。The trained model is converted to a single Trained Model module. 這會儲存在實驗畫布左側的模組選擇區。It's stored in the module palette to the left of the experiment canvas. 您可以在定型模型下找到此項目。You can find it under Trained Models.
  • 用於定型的模組已遭到移除,尤其是:Modules that were used for training are removed; specifically:
    • 定型模型Train Model
    • 分割資料Split Data
    • 評估模型Evaluate Model
  • 儲存的定型模型會加回實驗中The saved trained model is added back into the experiment
  • 將會新增 Web 服務輸入Web 服務輸出模組。Web service input and Web service output modules are added. 這些模組會識別使用者資料將在何處輸入模型,以及資料會傳回何處。These modules identify where the user's data will enter the model, and where data is returned.

您可以看到,實驗已在實驗畫布頂端的新索引標籤下儲存為兩個部分。You can see that the experiment is saved in two parts under the new tabs at the top of the experiment canvas. 原始的訓練實驗位於 [訓練實驗] 索引標籤底下,新建立的預測實驗位於 [預測實驗] 底下。The original training experiment is under the tab Training experiment, and the newly created predictive experiment is under Predictive experiment. 您將預測實驗部署為 Web 服務。The predictive experiment is the one you'll deploy as a web service.

實驗現在看起來如下:Your experiment should now look like this:

實驗在準備好進行部署之後的預期組態螢幕擷取畫面

最後一次執行實驗 (選取 [執行] )。Run the experiment one last time (select Run). 在快顯對話方塊中,選擇您要在其中執行實驗的計算目標。Choose the compute target you want the experiment to run on in the popup dialog. 若要確認模型仍然有效,請選取評分模型模組的輸出,並選取 [檢視結果] 。To verify the model is still working, select the output of the Score Model module and select View Results. 您可以看到原始資料顯示,以及預測的價格 (「評分標籤」)。You can see the original data is displayed, along with the predicted price ("Scored Labels").

部署 Web 服務Deploy the web service

部署衍生自您實驗的新式 Web 服務:To deploy a New web service derived from your experiment:

  1. 在畫布下方選取 [部署 Web 服務] 。Select Deploy Web Service below the canvas.

  2. 選取要執行您 Web 服務的計算目標Select the Compute Target that you'd like to run your web service.

    目前,視覺化介面僅支援對 Azure Kubernetes Service (AKS) 計算目標進行部署。Currently, the visual interface only supports deployment to Azure Kubernetes Service (AKS) compute targets. 您可以在機器學習服務工作區中選擇可用的 AKS 計算目標,或是使用所顯示對話方塊中的步驟來設定新的 AKS 環境。You can choose from available AKS compute targets in your machine learning service workspace or configure a new AKS environment using the steps in the dialogue that appears.

    顯示新計算目標可能組態的螢幕擷取畫面

  3. 選取 [部署 Web 服務] 。Select Deploy Web Service. 部署完成時,您會看到下列通知。You'll see the following notification when deployment completes. 部署可能需要幾分鐘的時間。Deployment may take a few minutes.

    顯示部署成功確認訊息的螢幕擷取畫面。

測試 Web 服務Test the web service

使用者輸入資料會透過 Web 服務輸入模組進入您已部署的模型。User input data enters your deployed model through the Web service input module. 接著,輸入會在評分模型模組中進行評分。The input is then scored in the Score Model module. 基於您設定預測實驗的方式,模型預期會得到與原始汽車價格資料集相同格式的資料。The way you've set up the predictive experiment, the model expects data in the same format as the original automobile price dataset. 最後,透過 Web 服務輸出模組,將結果傳回給使用者。Finally, the results are returned to the user through the Web service output module.

您可以在視覺化介面中的 Web 服務索引標籤中測試 Web 服務。You can test a web service in the web service tab in the visual interface.

  1. 移至 Web 服務區段。Go to the web service section. 您會看到您部署的 Web 服務,其名稱為教學課程 - 預測汽車價格 [預測實驗]You'll see the web service you deployed with the name Tutorial - Predict Automobile Price[Predictive Exp].

    醒目提示最近所建立 Web 服務的 Web 服務所引標籤螢幕擷取畫面

  2. 選取 Web 服務名稱以檢視其他詳細資料。Select the web service name to view additional details.

    Web 服務檢視中其他可用的詳細資料螢幕擷取畫面

  3. 選取 [測試] 。Select Test.

    顯示 Web 服務測試頁面的螢幕擷取畫面

  4. 輸入測試資料或使用自動填入的範例資料,然後選取底部的 [測試] 。Input testing data or use the autofilled sample data and select Test at the bottom. 測試要求會傳送至 Web 服務,而結果會顯示在頁面上。The test request is submitted to the web service and the results are shown on page. 雖然對輸入資料會產生價格值,但該值並不會用來產生預測值。Although a price value is generated for the input data, it is not used to generate the prediction value.

管理 Web 服務Manage the web service

一旦部署 Web 服務之後,您就可以從視覺化介面的 [Web 服務] 索引標籤中進行管理。Once you've deployed your web service, you can manage it from the Web Services tab in the visual interface.

若要刪除 Web 服務,您可以在 Web 服務詳細資料頁面中選取 [刪除] 。You can delete a web service by selecting Delete in the web service detail page.

顯示視窗底部刪除 Web 服務按鈕位置的螢幕擷取畫面

取用 Web 服務Consume the web service

在本教學課程的前幾個步驟中,您已將汽車預測模型部署為 Azure Web 服務。In the previous steps of this tutorial, you deployed an automobile prediction model as an Azure web service. 現在,使用者可以透過 REST API 將資料傳送至服務並接收結果。Now users can send data to it and receive results via REST API.

要求/回應 - 使用者可以使用 HTTP 通訊協定,將一列或多列汽車資料傳送至服務。Request/Response - The user sends one or more rows of automobile data to the service by using an HTTP protocol. 服務會回應一組或多組結果。The service responds with one or more sets of results.

您可以在 Web 服務詳細資料頁面的 [取用] 索引標籤中,找到 REST 呼叫範例。You can find sample REST calls in the Consume tab of the web service details page.

使用者可以在 [取用] 索引標籤中找到的 REST 呼叫範例螢幕擷取畫面

瀏覽至 [API 文件] 索引標籤,以尋找更多 API 詳細資料。Navigate to the API Doc tab, to find more API details.

使用者可以在 [API 文件] 索引標籤中找到其他 API 詳細資料的螢幕擷取畫面

在 Azure Machine Learning 服務工作區中管理模型和部署Manage models and deployments in Azure Machine Learning service workspace

您可以透過 Azure Machine Learning 服務工作區來管理在視覺化介面中建立的模型和 Web 服務部署。The models and web service deployments you create in the visual interface can be managed from the Azure Machine Learning service workspace.

  1. Azure 入口網站中開啟工作區。Open your workspace in the Azure portal.

  2. 在您的工作區中,選取 [模型] 。In your workspace, select Models. 然後選取您建立的實驗。Then select the experiment you created.

    示範如何在 Azure 入口網站中瀏覽至實驗的螢幕擷取畫面

    在此頁面上,您會看到模型的其他詳細資料。On this page, you'll see additional details about the model.

    在 Azure 入口網站中顯示實驗統計資料概觀的螢幕擷取畫面

  3. 選取 [部署] ,這會列出使用模型的任何 Web 服務。Select Deployments, it will list any web services that use the model. 選取 Web 服務名稱,即可移至 Web 服務的詳細資料頁面。Select the web service name, it will go to web service detail page. 在此頁面上,您可以取得更詳細的 Web 服務資訊。In this page, you can get more detailed information of the web service.

    詳細執行報告的螢幕擷取畫面

清除資源Clean up resources

重要

您可以使用您所建立的資源來作為其他 Azure Machine Learning 服務教學課程和操作說明文章的先決條件。You can use the resources that you created as prerequisites for other Azure Machine Learning service tutorials and how-to articles.

刪除所有內容Delete everything

如果您不打算使用您所建立的任何資源,請刪除整個資源群組,以免產生任何費用:If you don't plan to use anything that you created, delete the entire resource group so you don't incur any charges:

  1. 在 Azure 入口網站中,於視窗左側選取 [資源群組] 。In the Azure portal, select Resource groups on the left side of the window.

    在 Azure 入口網站中刪除資源群組

  2. 在清單中,選取您所建立的資源群組。In the list, select the resource group that you created.

  3. 在視窗的右側,選取省略符號按鈕 ( ... )。On the right side of the window, select the ellipsis button (...).

  4. 選取 [刪除資源群組] 。Select Delete resource group.

刪除資源群組同時會刪除您在視覺化介面中所建立的所有資源。Deleting the resource group also deletes all resources that you created in the visual interface.

僅刪除計算目標Delete only the compute target

您在這裡建立的計算目標會在不使用時自動調整為零個節點。The compute target that you created here automatically autoscales to zero nodes when it's not being used. 這是為了盡量降低費用。This is to minimize charges. 如果您想要刪除計算目標,請採取下列步驟: If you want to delete the compute target, take these steps:

  1. Azure 入口網站中,開啟您的工作區。In the Azure portal, open your workspace.

    刪除計算目標

  2. 在工作區的 [計算] 區段中選取資源。In the Compute section of your workspace, select the resource.

  3. 選取 [刪除] 。Select Delete.

刪除個別資產Delete individual assets

在實驗建立所在的視覺化介面中,藉由選取個別資產再選取 [刪除] 按鈕,即可刪除個別資產。In the visual interface where you created your experiment, delete individual assets by selecting them and then selecting the Delete button.

刪除實驗

後續步驟Next steps

在本教學課程中,您已了解在視覺化介面中建立、部署和使用機器學習模型的關鍵步驟。In this tutorial, you learned the key steps in creating, deploying, and consuming a machine learning model in the visual interface. 若要深入了解如何使用視覺化介面來解決其他類型的問題,請參閱範例實驗。To learn more about how you can use the visual interface to solve other types of problems, check out the sample experiments.