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

快速入门:通过基于云的 Notebook 服务器开始使用 Azure 机器学习Quickstart: Use a cloud-based notebook server to get started with Azure Machine Learning

无需安装任何软件。No install required. 通过在云中使用托管笔记本服务器开始使用 Azure 机器学习服务。Get started with Azure Machine Learning service using a managed notebook server in the cloud. 如果希望改为将 SDK 安装到你自己的 Python 环境中,请参阅快速入门:通过自己的 Notebook 服务器开始使用 Azure 机器学习If you want to instead install the SDK into your own Python environment, see Quickstart: Use your own notebook server to get started with Azure Machine Learning.

本快速入门展示了如何使用 Azure 机器学习服务工作区来跟踪你的机器学习试验。This quickstart shows how you can use the Azure Machine Learning service workspace to keep track of your machine learning experiments. 你将创建一个笔记本 VM(预览版),它是一个安全的基于云的 Azure 工作站,它提供 Jupyter 笔记本服务器、JupyterLab 和一个完全准备好的 ML 环境。You will create a notebook VM (Preview), a secure, cloud-based Azure workstation that provides a Jupyter notebook server, JupyterLab, and a fully prepared ML environment. 然后,在此 VM 上运行一个 Python 笔记本,用以将值记录到工作区中。You then run a Python notebook on this VM that log values into the workspace.

在本快速入门中,你将执行以下操作:In this quickstart, you take the following actions:

  • 创建工作区Create a workspace
  • 在你的工作区中创建一个笔记本 VM。Create a notebook VM in your workspace.
  • 启动 Jupyter Web 界面。Launch the Jupyter web interface.
  • 打开一个笔记本,其中包含的代码可以在每次迭代时消除 pi 和日志错误。Open a notebook that contains code to estimate pi and logs errors at each iteration.
  • 运行笔记本。Run the notebook.
  • 在工作区中查看所记录的错误值。View the logged error values in your workspace. 该示例介绍如何通过工作区跟踪脚本中生成的信息。This example shows how the workspace can help you keep track of information generated in a script.

如果没有 Azure 订阅,请在开始之前创建一个免费帐户。If you don’t have an Azure subscription, create a free account before you begin. 立即试用 Azure 机器学习服务免费版或付费版Try the free or paid version of Azure Machine Learning service today.

创建工作区Create a workspace

如果你有一个 Azure 机器学习服务工作区,请跳至下一部分If you have an Azure Machine Learning service workspace, skip to the next section. 否则,请立即创建一个。Otherwise, create one now.

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

    Azure 门户

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

    在 Azure 门户中创建资源

  3. 使用搜索栏来选择“机器学习服务工作区” 。Use the search bar, to select Machine Learning service workspace.

    搜索工作区

  4. 在“ML 服务工作区”窗格中,选择“创建”以开始 。In the ML service workspace pane, select Create to begin.

    “创建”按钮

  5. 在“机器学习服务工作区”窗格中,配置工作区 。In the ML service workspace pane, configure your 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 differentiate from workspaces created by others.
    SubscriptionSubscription 选择要使用的 Azure 订阅。Select the Azure subscription that you want to use.
    Resource groupResource 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. 这是用于创建工作区的位置。This location is where the workspace is created.
  6. 查看工作区配置,然后选择“创建” 。Review your workspace configuration, and select Create. 创建工作区可能需要一些时间。It can take a few moments to create the workspace.

  7. 完成创建后,会显示部署成功消息。When the process is finished, a deployment success message appears. 通知部分也会出现该消息。It's also present in the notifications section. 若要查看新工作区,请选择“转到资源” 。To view the new workspace, select Go to resource.

    工作区创建状态

创建笔记本 VMCreate a notebook VM

在工作区中创建云资源,以便开始使用 Jupyter 笔记本。From your workspace, you create a cloud resource to get started using Jupyter notebooks. 此服务提供一个基于云的平台,该平台已预先配置了运行 Azure 机器学习服务所需的一切。This resource gives you a cloud-based platform pre-configured with everything you need to run Azure Machine Learning service.

  1. Azure 门户中打开你的工作区。Open your workspace in the Azure portal. 如果不确定如何在门户中查找工作区,请参阅如何查找工作区If you're not sure how to locate your workspace in the portal, see how to find your workspace.

  2. 在 Azure 门户的工作区页上,选择左侧的“笔记本 VM”。 On your workspace page in the Azure portal, select Notebook VMs on the left.

  3. 选择“+新建”,创建一个笔记本 VM。 Select +New to create a notebook VM.

    选择“新建 VM”

  4. 为 VM 提供一个名称。Provide a name for your VM. 然后选择“创建” 。Then select Create.

    备注

    笔记本 VM 名称必须为 2 到 16 个字符。Your Notebook VM name must be between 2 to 16 characters. 有效字符为字母、数字和 - 字符。Valid characters are letters, digits, and the - character. 名称还必须在 Azure 订阅中独一无二。The name must also be unique across your Azure subscription.

    创建新 VM

  5. 等待约 4-5 分钟,直至状态更改为“正在运行”。 Wait approximately 4-5 minutes, until the status changes to Running.

启动 Jupyter Web 界面Launch Jupyter web interface

在 VM 运行以后,使用“笔记本 VM”部分启动 Jupyter Web 界面。 After your VM is running, use the Notebook VMs section to launch the Jupyter web interface.

  1. 在 VM 的“URI”列中选择“Jupyter”。 Select Jupyter in the URI column for your VM.

    启动 Jupyter 笔记本服务器

    此链接启动笔记本服务器并在新的浏览器标签页中打开 Jupyter 笔记本网页。此链接将仅适用于创建 VM 的人。The link starts your notebook server and opens the Jupyter notebook webpage in a new browser tab. This link will only work for the person who creates the VM.

  2. 在 Jupyter 笔记本网页上,顶部文件夹名称为用户名。On the Jupyter notebook webpage, the top foldername is your username. 选择该文件夹。Select this folder.

    提示

    此文件夹位于工作区中的存储容器上,而不是位于笔记本 VM 本身上。This folder is located on the storage container in your workspace rather than on the notebook VM itself. 可以删除笔记本 VM,但仍保留所有工作。You can delete the notebook VM and still keep all your work. 稍后创建新的笔记本 VM 时,它将加载此同一文件夹。When you create a new notebook VM later, it will load this same folder.

  3. samples 文件夹名称包含版本号,例如 samples-1.0.33.1The samples foldername includes a version number, for example samples-1.0.33.1. 选择 samples 文件夹。Select the samples folder.

  4. 选择 quickstart 文件夹。Select the quickstart folder.

运行笔记本Run the notebook

运行一个笔记本,估算 pi 并将错误记录到工作区。Run a notebook that estimates pi and logs the error to your workspace.

  1. 选择 01.run-experiment.ipynb 以打开笔记本。Select 01.run-experiment.ipynb to open the notebook.

  2. 如果看到“未找到内核”警报,请选择内核“Python 3.6 - AzureML” (大约位于列表的中间位置)并设置内核。If you see a "Kernel not found" alert, select the kernel Python 3.6 - AzureML (approximately mid-way down the list) and set the kernel.

  3. 单击第一个代码单元,然后选择“运行”。 Click into the first code cell and select Run.

    备注

    代码单元之前有括号。Code cells have brackets before them. 如果括号是空的 ( [ ] ),则表明代码尚未运行。If the brackets are empty ([ ]), the code has not been run. 运行代码时,会看到一个星号 ( [*] )。While the code is running, you see an asterisk([*]). 代码完成后,会显示一个数字 [1]After the code completes, a number [1] appears. 该数字表明单元的运行顺序。The number tells you the order in which the cells ran.

    使用 Shift-Enter 作为运行某个单元的快捷方式。Use Shift-Enter as a shortcut to run a cell.

    运行第一个代码单元

  4. 运行第二个代码单元。Run the second code cell. 如果看到身份验证说明,请复制代码,然后单击登录链接。If you see instructions to authenticate, copy the code and follow the link to sign in. 登录后,浏览器会记住该设置。Once you sign in, your browser will remember this setting.

    身份验证

  5. 完成后,会显示单元编号 [2]When complete, the cell number [2] appears. 如果已登录过,则会看到一条表明身份验证成功的状态消息。If you had to sign in, you will see a successful authentication status message. 如果未登录过,则不会看到此单元的任何输出,只会看到编号,表明该单元已成功运行。If you didn't have to sign in, you won't see any output for this cell, only the number appears to show that the cell ran successfully.

    成功消息

  6. 运行余下的代码单元。Run the rest of the code cells. 当每个单元完成运行时,会看到其单元编号显示。As each cell finishes running, you will see its cell number appear. 只有最后一个单元显示任意其他输出。Only the last cell displays any other output.

    在最大的代码单元中,会看到 run.log 在多个位置使用。In the largest code cell, you see run.log used in multiple places. 每个 run.log 都会将其值添加到工作区。Each run.log adds its value to your workspace.

查看所记录的值View logged values

  1. run 单元的输出包含一个可以返回到 Azure 门户的链接,用于在工作区中查看试验结果。The output from the run cell contains a link back to the Azure portal to view the experiment results in your workspace.

    查看试验

  2. 单击“链接到 Azure 门户”,查看在工作区中的运行的相关信息。 Click the Link to Azure portal to view information about the run in your workspace. 此链接打开 Azure 门户中的工作区。This link opens your workspace in the Azure portal.

  3. 你看到的已记录值的绘图已自动在工作区中创建。The plots of logged values you see were automatically created in the workspace. 只要使用相同的名称参数记录了多个值,系统就会自动为你生成绘图。Whenever you log multiple values with the same name parameter, a plot is automatically generated for you. 下面是一个示例:Here is an example:

    查看历史记录

由于估算 pi 的代码使用随机值,因此你的绘图可能看起来不同。Because the code to approximate pi uses random values, your plots may look different.

清理资源Clean up resources

停止笔记本 VMStop the notebook VM

在不使用笔记本 VM 时,请将其停止,以便降低成本。Stop the notebook VM when you are not using it to reduce cost.

  1. 在工作区中,选择“笔记本 VM”。 In your workspace, select Notebook VMs.

    停止 VM 服务器

  2. 从列表中选择 VM。From the list, select the VM.

  3. 选择“停止” 。Select Stop.

  4. 准备好再次使用服务器时,选择“启动” 。When you're ready to use the server again, select Start.

删除所有内容Delete everything

重要

已创建的资源可以用作其他 Azure 机器学习服务教程和操作方法文章的先决条件。The resources you created can be used as prerequisites to other Azure Machine Learning service tutorials and how-to articles.

如果不打算使用已创建的资源,请删除它们,以免产生任何费用:If you don't plan to use the resources you created, delete them, so you don't incur any charges:

  1. 在 Azure 门户中,选择最左侧的“资源组” 。In the Azure portal, select Resource groups on the far left.

    在 Azure 门户中删除

  2. 从列表中选择已创建的资源组。From the list, select the resource group you created.

  3. 选择“删除资源组” 。Select Delete resource group.

  4. 输入资源组名称。Enter the resource group name. 然后选择“删除” 。Then select Delete.

还可保留资源组,但请删除单个工作区。You can also keep the resource group but delete a single workspace. 显示工作区属性,然后选择“删除” 。Display the workspace properties and select Delete.

后续步骤Next steps

在本快速入门中,我们完成了以下任务:In this quickstart, you completed these tasks:

  • 创建工作区Create a workspace
  • 创建笔记本 VM。Create a notebook VM.
  • 启动 Jupyter Web 界面。Launch the Jupyter web interface.
  • 打开一个笔记本,其中包含的代码可以在每次迭代时消除 pi 和日志错误。Open a notebook that contains code to estimate pi and logs errors at each iteration.
  • 运行笔记本。Run the notebook.
  • 在工作区中查看所记录的错误值。View the logged error values in your workspace. 该示例介绍如何通过工作区跟踪脚本中生成的信息。This example shows how the workspace can help you keep track of information generated in a script.

在 Jupyter Notebook 网页的 quickstart 文件夹中,打开并运行 02.deploy-web-service.ipynb 笔记本,以了解如何部署 Web 服务。On the Jupyter Notebook webpage, in the quickstart folder, open and run the 02.deploy-web-service.ipynb notebook to learn how to deploy a web service.

同样在 Jupyter Notebook 网页上浏览 samples 文件夹中的其他笔记本,以详细了解 Azure 机器学习服务。Also on the Jupyter Notebook webpage, browse through other notebooks in the samples folder to learn more about Azure Machine Learning service.

若要深入体验工作流,请按照机器学习教程来训练和部署模型:For an in-depth workflow experience, follow Machine Learning tutorials to train and deploy a model: