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

快速入门:通过自己的 Notebook 服务器开始使用 Azure 机器学习Quickstart: Use your own notebook server to get started with Azure Machine Learning

通过你自己的 Python 环境和 Jupyter Notebook 服务器开始使用 Azure 机器学习服务。Use your own Python environment and Jupyter Notebook Server to get started with Azure Machine Learning service. 有关不需安装 SDK 的快速入门,请参阅快速入门:通过基于云的 Notebook 服务器开始使用 Azure 机器学习For a quickstart with no SDK installation, see Quickstart: Use a cloud-based 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. 你将运行 Python 代码,用以将值记录到工作区中。You will run Python code that log values into the workspace.

观看本快速入门的视频版本:View a video version of this quickstart:

如果没有 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.

先决条件Prerequisites

  • 一个安装了 Azure 机器学习 SDK 的 Python 3.6 Notebook 服务器A Python 3.6 notebook server with the Azure Machine Learning SDK installed
  • 一个 Azure 机器学习服务工作区An Azure Machine Learning service workspace
  • 一个工作区配置文件 (.azureml/config.json) 。A workspace configuration file (.azureml/config.json).

创建 Azure 机器学习服务工作区获取所有这些先决条件。Get all these prerequisites from Create an Azure Machine Learning service workspace.

使用工作区Use the workspace

在工作区配置文件 (.azureml/config.json) 所在目录中创建一个脚本或启动一个笔记本。Create a script or start a notebook in the same directory as your workspace configuration file (.azureml/config.json).

附加到工作区Attach to workspace

此代码从要附加到工作区的配置文件中读取信息。This code reads information from the configuration file to attach to your workspace.

from azureml.core import Workspace

ws = Workspace.from_config()

记录值Log values

运行使用 SDK 基本 API 来跟踪试验运行的代码。Run this code that uses the basic APIs of the SDK to track experiment runs.

  1. 在工作区中创建一个试验。Create an experiment in the workspace.
  2. 将单个值记录到试验中。Log a single value into the experiment.
  3. 将值列表记录到试验中。Log a list of values into the experiment.
from azureml.core import Experiment

# Create a new experiment in your workspace.
exp = Experiment(workspace=ws, name='myexp')

# Start a run and start the logging service.
run = exp.start_logging()

# Log a single  number.
run.log('my magic number', 42)

# Log a list (Fibonacci numbers).
run.log_list('my list', [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]) 

# Finish the run.
run.complete()

查看记录的结果View logged results

运行完成后,可在 Azure 门户中查看试验运行。When the run finishes, you can view the experiment run in the Azure portal. 使用以下代码打印导航至最后一次运行的结果的 URL:To print a URL that navigates to the results for the last run, use the following code:

print(run.get_portal_url())

此代码返回一个链接,你可以使用该链接在浏览器中查看 Azure 门户中记录的值。This code returns a link you can use to view the logged values in the Azure portal in your browser.

Azure 门户中记录的值

清理资源Clean up resources

重要

可以使用此处已创建的资源作为其他机器学习教程和操作方法文章的先决条件。You can use the resources you've created here as prerequisites to other Machine Learning tutorials and how-to articles.

如果不打算使用本文中创建的资源,请删除它们,以免产生任何费用。If you don't plan to use the resources that you created in this article, delete them to avoid incurring any charges.

ws.delete(delete_dependent_resources=True)

后续步骤Next steps

在本文中,你创建了进行试验和部署模型所需的资源。In this article, you created the resources you need to experiment with and deploy models. 在 Notebook 中运行了代码,并在云端工作区中浏览了该代码的运行历史记录。You ran code in a notebook, and you explored the run history for the code in your workspace in the cloud.

还可以学习 GitHub 中的更高级示例或查看 SDK 用户指南You can also explore more advanced examples on GitHub or view the SDK user guide.