机器学习工作室(经典)模型如何从试验逐步演变为 Web 服务How a Machine Learning Studio (classic) model progresses from an experiment to a Web service

适用于: yes机器学习工作室(经典) noAzure 机器学习APPLIES TO: yesMachine Learning Studio (classic) noAzure Machine Learning

Azure 机器学习工作室(经典)提供交互式画布,使你能开发、运行、测试和迭代表示预测分析模型的试验。Azure Machine Learning Studio (classic) provides an interactive canvas that allows you to develop, run, test, and iterate an experiment representing a predictive analysis model. 有大量各种不同的模块可用于:There are a wide variety of modules available that can:

  • 将数据输入到实验Input data into your experiment
  • 操作该数据Manipulate the data
  • 使用机器学习算法训练模型Train a model using machine learning algorithms
  • 为模型评分Score the model
  • 评估结果Evaluate the results
  • 输出最终值Output final values

一旦你对试验感到满意,则可以将其部署为经典 Azure 机器学习 Web 服务或新的 Azure 机器学习 Web 服务,以便用户可以向其发送新的数据,并接收返回的结果。Once you're satisfied with your experiment, you can deploy it as a Classic Azure Machine Learning Web service or a New Azure Machine Learning Web service so that users can send it new data and receive back results.

在本文中,我们提供了有关机器学习模型如何从开发实验逐步进展为运营 Web 服务的机制概述。In this article, we give an overview of the mechanics of how your Machine Learning model progresses from a development experiment to an operationalized Web service.

备注

还有其他方法可用于开发和部署机器学习模型,但本文的重点是如何使用机器学习工作室(经典)。There are other ways to develop and deploy machine learning models, but this article is focused on how you use Machine Learning Studio (classic). 例如,若要阅读如何使用 R 创建经典预测 Web 服务的说明,请参阅博客文章使用 RStudio 和 Azure 机器学习工作室生成和部署预测 Web 应用For example, to read a description of how to create a classic predictive Web service with R, see the blog post Build & Deploy Predictive Web Apps Using RStudio and Azure Machine Learning studio.

虽然 Azure 机器学习工作室(经典)主要是用于帮助你开发和部署预测分析模型,但也可以使用它来开发不包括预测分析模型的试验。While Azure Machine Learning Studio (classic) is designed to help you develop and deploy a predictive analysis model, it's possible to use Studio (classic) to develop an experiment that doesn't include a predictive analysis model. 例如,实验可能只是输入数据,对其进行操作,并输出结果。For example, an experiment might just input data, manipulate it, and then output the results. 就像预测分析试验一样,可以将此非预测试验部署为 Web 服务,但它是一个更简单的过程,因为试验不会对机器学习模型进行训练或评分。Just like a predictive analysis experiment, you can deploy this non-predictive experiment as a Web service, but it's a simpler process because the experiment isn't training or scoring a machine learning model. 尽管这不是使用工作室(经典)的典型方法,但我们会在讨论中探讨它,以便可以提供有关工作室(经典)工作原理的完整说明。While it's not the typical to use Studio (classic) in this way, we'll include it in the discussion so that we can give a complete explanation of how Studio (classic) works.

开发和部署预测性 Web 服务Developing and deploying a predictive Web service

以下是在使用机器学习工作室(经典)进行开发和部署时典型解决方案所遵循的各个阶段:Here are the stages that a typical solution follows as you develop and deploy it using Machine Learning Studio (classic):

部署流

图 1 - 典型预测分析模型的各个阶段Figure 1 - Stages of a typical predictive analysis model

训练实验The training experiment

训练实验是在机器学习工作室(经典)中开发 Web 服务的初始阶段。The training experiment is the initial phase of developing your Web service in Machine Learning Studio (classic). 训练实验的目的是提供一个开发、测试、循环访问和最终定型机器学习模型的环境。The purpose of the training experiment is to give you a place to develop, test, iterate, and eventually train a machine learning model. 在寻找最佳解决方案时,甚至可以同时训练多个模型,但完成实验后,将选择一个定型模型,并去除实验中的其余部分。You can even train multiple models simultaneously as you look for the best solution, but once you’re done experimenting you’ll select a single trained model and eliminate the rest from the experiment. 有关开发预测分析实验的示例,请参阅在 Azure 机器学习工作室(经典)中为信用风险评估开发预测分析解决方案For an example of developing a predictive analysis experiment, see Develop a predictive analytics solution for credit risk assessment in Azure Machine Learning Studio (classic).

预测性实验The predictive experiment

在训练实验中具有已训练的模型后,在机器学习工作室(经典)中单击“设置 Web 服务”,然后选择“预测性 Web 服务”,以启动将训练实验转换为预测性实验的过程 。Once you have a trained model in your training experiment, click Set Up Web Service and select Predictive Web Service in Machine Learning Studio (classic) to initiate the process of converting your training experiment to a predictive experiment. 预测性实验旨在使用定型模型对新数据进行评分,目的是为了最终变得如 Azure Web 服务一样具备可操作性。The purpose of the predictive experiment is to use your trained model to score new data, with the goal of eventually becoming operationalized as an Azure Web service.

会通过以下步骤完成该转换:This conversion is done for you through the following steps:

  • 将用于训练的模块集转换为单个模块,并将其另存为定型模型Convert the set of modules used for training into a single module and save it as a trained model
  • 去除任何与评分不相关的多余模块Eliminate any extraneous modules not related to scoring
  • 添加最终 Web 服务将使用的输入和输出端口Add input and output ports that the eventual Web service will use

可能你会有想要执行的其他更改,以使预测试验准备好部署为 Web 服务。There may be more changes you want to make to get your predictive experiment ready to deploy as a Web service. 例如,如果想要 Web 服务仅输出结果的一部分,可以在输出端口前添加筛选模块。For example, if you want the Web service to output only a subset of results, you can add a filtering module before the output port.

在此转换过程中,不会放弃训练实验。In this conversion process, the training experiment is not discarded. 该过程完成后,工作室(经典)中有两个选项卡:一个用于训练实验,一个用于预测实验。When the process is complete, you have two tabs in Studio (classic): one for the training experiment and one for the predictive experiment. 通过此方法,在部署 Web 服务之前,可以更改训练实验,并重新生成预测实验。This way you can make changes to the training experiment before you deploy your Web service and rebuild the predictive experiment. 也可以保存一份训练实验副本,以开始另一行的实验。Or you can save a copy of the training experiment to start another line of experimentation.

备注

单击“预测 Web 服务”时,会启动将训练实验转换为预测实验的自动进程,并且这在大多数情况下可正常运行。When you click Predictive Web Service you start an automatic process to convert your training experiment to a predictive experiment, and this works well in most cases. 如果训练实验过于复杂(例如,有多种联合使用的训练途径),可能需要手动执行此转换。If your training experiment is complex (for example, you have multiple paths for training that you join together), you might prefer to do this conversion manually. 有关详细信息,请参阅如何准备模型以便在 Azure 机器学习工作室(经典)中进行部署For more information, see How to prepare your model for deployment in Azure Machine Learning Studio (classic).

Web 服务The web service

预测实验准备就绪让你感到满意后,即可基于 Azure 资源管理器将服务部署为经典 Web 服务或新的 Web 服务。Once you're satisfied that your predictive experiment is ready, you can deploy your service as either a Classic Web service or a New Web service based on Azure Resource Manager. 要通过将其部署为经典机器学习 Web 服务来实施模型,请单击“部署 Web 服务”,然后选择“部署 Web 服务[经典] ”。To operationalize your model by deploying it as a Classic Machine Learning Web service, click Deploy Web Service and select Deploy Web Service [Classic]. 要作为新的机器学习 Web 服务进行部署,请单击“部署 Web 服务”,并选择“部署 Web 服务[新] ”。To deploy as New Machine Learning Web service, click Deploy Web Service and select Deploy Web Service [New]. 用户现在可以使用 Web 服务 REST API 将数据发送到模型并接收返回的结果。Users can now send data to your model using the Web service REST API and receive back the results. 有关详细信息,请参阅如何使用 Azure 机器学习 Web 服务For more information, see How to consume an Azure Machine Learning Web service.

非典型情况:创建一个非预测性的 Web 服务The non-typical case: creating a non-predictive Web service

如果实验没有对预测分析模型进行训练,则无需创建训练实验和评分实验 - 只有一个实验,并且可以将其部署为 Web 服务。If your experiment does not train a predictive analysis model, then you don't need to create both a training experiment and a scoring experiment - there's just one experiment, and you can deploy it as a Web service. 机器学习工作室(经典)可通过分析所使用的模块,检测实验是否包含预测性模型。Machine Learning Studio (classic) detects whether your experiment contains a predictive model by analyzing the modules you've used.

在迭代实验并感到满意后:After you've iterated on your experiment and are satisfied with it:

  1. 单击“设置 Web 服务”,然后选择“重新训练 Web 服务” - 会自动添加输入和输出节点Click Set Up Web Service and select Retraining Web Service - input and output nodes are added automatically
  2. 单击“运行Click Run
  3. 单击“部署 Web 服务”,并选择“部署 Web 服务[经典] ”或“部署 Web 服务[新] ”,具体取决于要部署的环境。Click Deploy Web Service and select Deploy Web Service [Classic] or Deploy Web Service [New] depending on the environment to which you want to deploy.

Web 服务现已部署,并且可以像预测的 Web 服务一样对其进行访问和管理。Your Web service is now deployed, and you can access and manage it just like a predictive Web service.

更新 Web 服务Updating your web service

至此,已经将实验部署为 Web 服务,如果需要更新它呢?Now that you've deployed your experiment as a Web service, what if you need to update it?

这取决于需要更新的内容:That depends on what you need to update:

是要更改输入或输出,还是要修改 Web 服务操作数据的方式You want to change the input or output, or you want to modify how the Web service manipulates data

如果不更改该模型,而只是更改 Web 服务处理数据的方式,则可以编辑预测试验,然后单击“部署 Web 服务”,再次选择“部署 Web 服务[经典]”或“部署 Web 服务[新]”。If you're not changing the model, but are just changing how the Web service handles data, you can edit the predictive experiment and then click Deploy Web Service and select Deploy Web Service [Classic] or Deploy Web Service [New] again. Web 服务将停止,会对更新的预测实验进行部署,并重新启动 Web 服务。The Web service is stopped, the updated predictive experiment is deployed, and the Web service is restarted.

下面是一个示例:假设预测试验返回输入数据的整个行与预测结果。Here's an example: Suppose your predictive experiment returns the entire row of input data with the predicted result. 可能决定想要 Web 服务只返回结果。You may decide that you want the Web service to just return the result. 那么,可以在预测实验中添加项目列,紧接在输出端口前,以排除除了结果之外的列。So you can add a Project Columns module in the predictive experiment, right before the output port, to exclude columns other than the result. 单击“部署 Web 服务”时,并再次选择“部署 Web 服务[经典] ”或“部署 Web 服务[新] ”,Web 服务将更新。When you click Deploy Web Service and select Deploy Web Service [Classic] or Deploy Web Service [New] again, the Web service is updated.

想要使用新数据重新训练模型You want to retrain the model with new data

如果要保留机器学习模型,但希望使用新数据对其进行重新训练,有两个选择:If you want to keep your machine learning model, but you would like to retrain it with new data, you have two choices:

  1. Web 服务运行时重新训练模型 - 如果要在预测 Web 服务正在运行时重新训练模型,可以通过对训练实验进行部分修改,以使其成为重新训练实验来完成此操作,然后可以将其部署为重新训练 Web 服务Retrain the model while the Web service is running - If you want to retrain your model while the predictive Web service is running, you can do this by making a couple modifications to the training experiment to make it a retraining experiment, then you can deploy it as a retraining web service. 有关如何执行此操作的说明,请参阅以编程方式重新训练机器学习模型For instructions on how to do this, see Retrain Machine Learning models programmatically.

  2. 返回原始训练实验并使用不同的训练数据来开发模型 - 预测实验链接到 Web 服务,但训练实验不是以此方式直接链接。Go back to the original training experiment and use different training data to develop your model - Your predictive experiment is linked to the Web service, but the training experiment is not directly linked in this way. 如果修改原始训练实验并单击“设置 Web 服务”,它将创建一个新的预测实验,在其部署时会创建一项新的 Web 服务。If you modify the original training experiment and click Set Up Web Service, it will create a new predictive experiment which, when deployed, will create a new Web service. 它不只是更新原始 Web 服务。It doesn't just update the original Web service.

    如果需要修改训练实验,请打开它并单击“另存为”以制作副本。If you need to modify the training experiment, open it and click Save As to make a copy. 这会使原始训练实验、预测实验和 Web 服务保持不变。This will leave intact the original training experiment, predictive experiment, and Web service. 现在可以使用更改来创建新的 Web 服务。You can now create a new Web service with your changes. 部署了新的 Web 服务后,可以决定是否要停止以前的 Web 服务,或使其与新的服务一起运行。Once you've deployed the new Web service you can then decide whether to stop the previous Web service or keep it running alongside the new one.

想要训练不同的模型You want to train a different model

如果想更改原始预测实验,如选择不同的计算机学习算法、尝试不同的训练方法等,则需要按照上述重新训练模型的第二个过程:打开培训实验,单击“另存为”来创建一个副本,并在新路径下开始开发模型、创建预测实验和部署 Web 服务。If you want to make changes to your original predictive experiment, such as selecting a different machine learning algorithm, trying a different training method, etc., then you need to follow the second procedure described above for retraining your model: open the training experiment, click Save As to make a copy, and then start down the new path of developing your model, creating the predictive experiment, and deploying the web service. 这会创建一个与原始 Web 服务无关的新的 Web 服务 - 可以决定运行其中一个,或两个都保持运行。This will create a new Web service unrelated to the original one - you can decide which one, or both, to keep running.

后续步骤Next steps

有关开发和实验过程的详细信息,请参阅以下文章:For more details on the process of developing and experiment, see the following articles:

有关整个过程的示例,请参阅:For examples of the whole process, see: