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

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

创建基于云的笔记本服务器,然后使用它。Create a cloud-based notebook server, then use it. 在本快速入门中,我们运行 Python 代码,在 Azure 机器学习服务工作区中记录值。In this quickstart, you run Python code that logs values in the Azure Machine Learning service workspace. 该工作区是基础的云端块,用于通过机器学习进行机器学习模型的试验、训练和部署。The workspace is the foundational block in the cloud that you use to experiment, train, and deploy machine learning models with Machine Learning.

本快速入门介绍如何在 Azure 机器学习工作区中创建云资源,该工作区已配置了运行 Azure 机器学习所需的 Python 环境。This quickstart shows how to create a cloud resource in your Azure Machine Learning workspace, configured with the Python environment necessary to run Azure Machine Learning. 若要改用自己的环境,请参阅快速入门:通过自己的 Notebook 服务器开始使用 Azure 机器学习To use your own environment instead, see Quickstart: Use your own notebook server to get started with Azure Machine Learning.

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

  • 在工作区中创建新的基于云的笔记本服务器。Create a new cloud-based notebook server 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. 在搜索栏中输入“机器学习”。In the search bar, enter Machine Learning. 选择搜索结果“机器学习服务工作区”。Select the Machine Learning service workspace search result.

    搜索工作区

  4. 在“机器学习服务工作区”窗格中,滚动到底部并选择“创建”。In the ML service workspace pane, scroll to the bottom and 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.
    订阅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 is a container that holds related resources for an Azure solution. 本示例使用 docs-aml。In this example, we use docs-aml.
    LocationLocation 选择最靠近用户和数据资源的位置。Select the location closest to your users and the data resources. 这是用于创建工作区的位置。This location is where the workspace is created.

    创建工作区

  6. 选择“创建”以开始进行创建。To start the creation process, select Create. 创建工作区可能需要一些时间。It can take a few moments to create the workspace.

  7. 若要检查部署状态,请选择工具栏上的“通知”图标(铃铛)。To check on the status of the deployment, select the Notifications icon, bell, on the toolbar.

  8. 完成创建后,会显示部署成功消息。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.

    工作区创建状态

创建基于云的笔记本服务器Create a cloud-based notebook server

在工作区中创建云资源,以便开始使用 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.

  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. 选择快速入门笔记本。Select the quickstart notebook.

运行笔记本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. 单击第一个代码单元,然后选择“运行”。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.

    运行第一个代码单元

  3. 运行第二个代码单元。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.

    身份验证

  4. 完成后,会显示单元编号 [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.

    成功消息

  5. 运行余下的代码单元。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.

    查看历史记录

由于估算 pi 的代码使用随机值,因此绘图会显示不同的值。Because the code to approximate pi uses random values, your plots will show different values.

清理资源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 user 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:

  • 创建笔记本 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 网页上浏览 samples 文件夹中的其他笔记本,详细了解 Azure 机器学习服务。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: