您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

教程:使用可视界面部署机器学习模型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 服务 (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 机器学习工作区管理在可视界面中创建的模型和 Web 服务部署。The models and web service deployments you create in the visual interface can also be managed from the Azure Machine Learning 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

也可以在工作区登陆页面(预览版)的“模型”和“终结点”部分中找到这些模型和部署 。You can also find these models and deployments in the Models and Endpoints sections of your workspace landing page (preview).

清理资源Clean up resources

重要

可以使用你创建的、用作其他 Azure 机器学习服务教程和操作指南文章的先决条件的资源。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.