教程:开始使用 Python SDK 创建第一个 ML 试验Tutorial: Get started creating your first ML experiment with the Python SDK

适用于:是基本版是企业版               (升级到企业版APPLIES TO: yesBasic edition yesEnterprise edition                    (Upgrade to Enterprise edition)

在本教程中,你将完成端到端的步骤,以开始使用 Jupyter Notebook 中运行的 Azure 机器学习 Python SDK。In this tutorial, you complete the end-to-end steps to get started with the Azure Machine Learning Python SDK running in Jupyter notebooks. 本教程是由两个部分组成的系列教程的第一部分,介绍如何设置和配置 Python 环境,以及如何创建工作区来管理试验模型和机器学习模型。This tutorial is part one of a two-part tutorial series, and covers Python environment setup and configuration, as well as creating a workspace to manage your experiments and machine learning models. 第二部分是在本文的基础上编写的,介绍如何训练多个机器学习模型,以及如何使用 Azure 机器学习工作室和 SDK 来管理模型 。Part two builds on this to train multiple machine learning models and introduce the model management process using both Azure Machine Learning studio and the SDK.

本教程介绍以下操作:In this tutorial, you:

  • 创建要在下一篇教程中使用的 Azure 机器学习工作区Create an Azure Machine Learning Workspace to use in the next tutorial.
  • 将教程笔记本克隆到工作区中的文件夹。Clone the tutorials notebook to your folder in the workspace.
  • 创建一个基于云的计算实例,其中已安装并预配置了 Azure 机器学习 Python SDK。Create a cloud-based compute instance with Azure Machine Learning Python SDK installed and pre-configured.

如果没有 Azure 订阅,请在开始之前创建一个试用帐户。If you don’t have an Azure subscription, create a trial account before you begin.

创建工作区Create a workspace

Azure 机器学习工作区是云中的基础资源,用于试验、训练和部署机器学习模型。An Azure Machine Learning workspace is a foundational resource in the cloud that you use to experiment, train, and deploy machine learning models. 它将 Azure 订阅和资源组关联到服务中一个易于使用的对象。It ties your Azure subscription and resource group to an easily consumed object in the service.

通过 Azure 门户创建工作区,该门户是用于管理 Azure 资源的基于 Web 的控制台。You create a workspace via the Azure portal, a web-based console for managing your Azure resources.

  1. 使用 Azure 订阅的凭据登录到 Azure 门户Sign in to Azure portal by using the credentials for your Azure subscription.

  2. 在 Azure 门户的左上角,选择“+ 创建资源” 。In the upper-left corner of Azure portal, select + Create a resource.

    创建新资源

  3. 使用搜索栏查找“机器学习” 。Use the search bar to find Machine Learning.

  4. 选择“机器学习” 。Select Machine Learning.

  5. 在“机器学习”窗格中,选择“创建”以开始 。In the Machine Learning pane, select Create to begin.

  6. 提供以下信息来配置新工作区:Provide the following information to configure your new workspace:

    字段Field 说明Description
    工作区名称Workspace name 输入用于标识工作区的唯一名称。Enter a unique name that identifies your workspace. 本示例使用 docs-ws 。In this example, we use docs-ws. 名称在整个资源组中必须唯一。Names must be unique across the resource group. 使用易于记忆且区别于其他人所创建工作区的名称。Use a name that's easy to recall and to differentiate from workspaces created by others.
    订阅Subscription 选择要使用的 Azure 订阅。Select the Azure subscription that you want to use.
    资源组Resource group 使用订阅中的现有资源组,或者输入一个名称以创建新的资源组。Use an existing resource group in your subscription or enter a name to create a new resource group. 资源组保存 Azure 解决方案的相关资源。A resource group holds related resources for an Azure solution. 本示例使用 docs-aml 。In this example, we use docs-aml.
    位置Location 选择离你的用户和数据资源最近的位置来创建工作区。Select the location closest to your users and the data resources to create your workspace.
    工作区版本Workspace edition 选择“基本” 作为本教程的工作区类型。Select Basic as the workspace type for this tutorial. 工作区类型(基本和企业)确定要访问的功能和定价。The workspace type (Basic & Enterprise) determines the features to which you’ll have access and pricing. 本教程中的所有内容均可使用基本或企业工作区来执行。Everything in this tutorial can be performed with either a Basic or Enterprise workspace.
  7. 完成工作区配置后,选择“查看 + 创建” 。After you are finished configuring the workspace, select Review + Create.

    Warning

    在云中创建工作区可能需要几分钟时间。It can take several minutes to create your workspace in the cloud.

    完成创建后,会显示部署成功消息。When the process is finished, a deployment success message appears.

  8. 若要查看新工作区,请选择“转到资源” 。To view the new workspace, select Go to resource.

Important

记下你的工作区和订阅 。Take note of your workspace and subscription. 你将需要这些项才能确保在正确的位置创建试验。You'll need these to ensure you create your experiment in the right place.

在工作区中运行笔记本Run notebook in your workspace

本教程使用工作区中的云笔记本服务器来实现免安装的预配置体验。This tutorial uses the cloud notebook server in your workspace for an install-free and pre-configured experience. 如果你希望控制环境、包和依赖项,请使用自己的环境Use your own environment if you prefer to have control over your environment, packages and dependencies.

克隆笔记本文件夹Clone a notebook folder

在 Azure 机器学习工作室中完成以下试验设置和运行步骤,该工作室是包含用于为所有技能级别的数据科学实践者执行数据科学方案的机器学习工具的合并界面。You complete the following experiment set-up and run steps in Azure Machine Learning studio, a consolidated interface that includes machine learning tools to perform data science scenarios for data science practitioners of all skill levels.

  1. 登录到 Azure 机器学习工作室Sign in to Azure Machine Learning studio.

  2. 选择创建的订阅和工作区。Select your subscription and the workspace you created.

  3. 选择左侧的“笔记本” 。Select Notebooks on the left.

  4. 打开“Samples”文件夹 。Open the Samples folder.

  5. 打开“Python”文件夹 。Open the Python folder.

  6. 打开包含版本号的文件夹。Open the folder with a version number on it. 此数字表示 Python SDK 的当前版本。This number represents the current release for the Python SDK.

  7. 选择 tutorials 文件夹右侧的“...”,然后选择“克隆”。 Select the "..." at the right of the tutorials folder and then select Clone.

    克隆文件夹

  8. 将显示文件夹列表,其中显示了访问工作区的每个用户。A list of folders displays showing each user who accesses the workspace. 选择要将“tutorials”文件夹克隆到其中的文件夹 。Select your folder to clone the tutorials folder there.

打开克隆的笔记本Open the cloned notebook

  1. 在“用户文件”下打开你的文件夹,然后打开克隆的“tutorials”文件夹。 Under User Files open your folder and then open the cloned tutorials folder.

    打开 tutorials 文件夹

    Important

    可以查看 samples 文件夹中的笔记本,但无法从此文件夹运行笔记本。You can view notebooks in the samples folder but you cannot run a notebook from there. 若要运行笔记本,请确保在“用户文件”部分打开笔记本的克隆版本。 In order to run a notebook, make sure you open the cloned version of the notebook in the User Files section.

  2. 选择 tutorials/create-first-ml-experiment 文件夹中的 tutorial-1st-experiment-sdk-train.ipynb 文件。Select the tutorial-1st-experiment-sdk-train.ipynb file in your tutorials/create-first-ml-experiment folder.

  3. 在顶部栏上,选择用来运行笔记本的计算实例。On the top bar, select a compute instance to use to run the notebook. 这些 VM 中已预先配置了运行 Azure 机器学习所需的一切设置These VMs are pre-configured with everything you need to run Azure Machine Learning. 可以选择任何工作区用户创建的 VM。You can select a VM created by any user of your workspace.

  4. 如果未找到任何 VM,请选择“+ 添加”来创建计算实例 VM 。If no VMs are found, select + Add to create the compute instance VM.

    1. 创建 VM 时请提供其名称。When you create a VM, provide a name. 该名称必须包含 2 到 16 个字符。The name must be between 2 to 16 characters. 有效字符为字母、数字和 - 字符。该名称必须在整个 Azure 订阅中唯一。Valid characters are letters, digits, and the - character, and must also be unique across your Azure subscription.

    2. 从可用选项中选择虚拟机大小。Select the Virtual Machine size from the available choices.

    3. 然后选择“创建” 。Then select Create. 设置 VM 可能需要大约 5 分钟时间。It can take approximately 5 minutes to set up your VM.

  5. VM 可用后,它将显示在顶部工具栏中。Once the VM is available it will be displayed in the top toolbar. 现在,可以使用工具栏中的“全部运行”,或者在笔记本的代码单元中按 Shift+Enter,来运行笔记本。 You can now run the notebook either by using Run all in the toolbar, or by using Shift+Enter in the code cells of the notebook.

如果你有自定义小工具或更喜欢使用 Jupyter/JupyterLab,请选择最右侧的 Jupyter 下拉菜单,然后选择 JupyterJupyterLabIf you have custom widgets or prefer using Jupyter/JupyterLab select the Jupyter drop down on the far right, then select Jupyter or JupyterLab. 此时将打开新的浏览器窗口。The new browser window will be opened.

后续步骤Next steps

在本教程中,你已完成以下任务:In this tutorial, you completed these tasks:

  • 创建了 Azure 机器学习工作区。Created an Azure Machine Learning workspace.
  • 在工作区中创建并配置了云笔记本服务器。Created and configured a cloud notebook server in your workspace.

在本教程的第二部分中,你将运行 tutorial-1st-experiment-sdk-train.ipynb 中的代码来训练机器学习模型。In part two of the tutorial you run the code in tutorial-1st-experiment-sdk-train.ipynb to train a machine learning model.

Important

如果你不打算按照本教程的第 2 部分或任何其他教程进行操作,则应该在不使用云笔记本服务器 VM 时停止它,以降低成本。If you do not plan on following part 2 of this tutorial or any other tutorials, you should stop the cloud notebook server VM when you are not using it to reduce cost.