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

為了讓其他人有機會使用教學課程第一部分中開發的預測模型,您可以將其部署為 Azure Web 服務。To give others a chance to use the predictive model developed in part one of the 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. 在教學課程的這個部分中,您將: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 to learn how to train and score a machine learning model in the visual interface.

準備部署Prepare for deployment

將實驗部署為 Web 服務之前,您必須先將「訓練實驗」 轉換成「預測實驗」 。Before you deploy your experiment as a web service, you first have to convert your training experiment into a predictive experiment.

  1. 請選取實驗畫布底端的 [建立預測實驗] *。Select Create Predictive Experiment* at the bottom of the experiment canvas.

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

    當您選取 [建立預測實驗] 時,有幾件事會發生:When you select Create Predictive Experiment, several things happen:

    • 定型的模型會儲存為模組選擇區中定型模型模組。The trained model is stored as a Trained Model module in the module palette. 您可以在定型模型下找到此項目。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 data will enter the model, and where data is returned.

    訓練實驗仍儲存在實驗畫布頂端的新索引標籤下。The training experiment is still saved under the new tabs at the top of the experiment canvas.

  2. 執行 實驗。Run the experiment.

  3. 請選取 [評分模型] 模組的輸出,並選取 [檢視結果] 來確認模型仍然有效。Select the output of the Score Model module and select View Results to verify the model is still working. 您可以看到原始資料顯示,以及預測的價格 (「評分標籤」)。You can see the original data is displayed, along with the predicted price ("Scored Labels").

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

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

部署 Web 服務Deploy the web service

  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 服務] 索引標籤,來測試和管理您視覺化介面的 Web 服務。You can test and manage your visual interface web services by navigating to the Web Services tab.

  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.

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

    顯示 Web 服務測試頁面的螢幕擷取畫面Screenshot showing the web service testing page

  4. 輸入測試資料或使用自動填入的範例資料,然後選取 [測試] 。Input testing data or use the autofilled sample data and select Test.

    測試要求會傳送至 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 服務Consume the web service

使用者現在可以將 API 要求傳送至您的 Azure Web 服務並接收結果,藉此預測新汽車的價格。Users can now send API requests to your Azure web service and receive results to predict the price of their new automobiles.

要求/回應 - 使用者可以使用 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.

管理模型和部署Manage models and deployments

您也可以透過 Azure Machine Learning 服務工作區來管理在視覺化介面中建立的模型和 Web 服務部署。The models and web service deployments you create in the visual interface can also 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.

  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.

    詳細執行報告的螢幕擷取畫面Screenshot detailed run report

您也可以在您工作區登陸頁面 (預覽) 的 [Models] (模型) 和 [Endpoints] (端點) 區段中找到這些模型和部署。You can also find these models and deployments in the Models and Endpoints sections of your workspace landing page (preview).

清除資源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, see out our other sample experiments.