建立 Azure 機器學習服務工作區Create an Azure Machine Learning service workspace

若要使用 Azure Machine Learning 服務,您需要 Azure Machine Learning 服務工作區To use Azure Machine Learning service, you need an Azure Machine Learning service workspace. 此工作區是服務的最上層資源,並提供您要使用您所建立的所有成品的集中位置。This workspace is the top-level resource for the service and provides you with a centralized place to work with all the artifacts you create.

在本文中,您會學習如何建立工作區中使用任何一種方法:In this article, you learn how to create a workspace using any of these methods:

您使用這裡中的步驟建立的工作區可用來當做其他教學課程和 how-to 文章的必要條件。The workspace you create using the steps here-in can be used as a prerequisite to other tutorials and how-to articles.

如果您想要使用指令碼設定自動化的機器學習服務中的本機 Python 環境,請參閱Azure/MachineLearningNotebooks GitHub如需相關指示。If you would like to use a script to setup automated machine learning in a local Python environment please refer to the Azure/MachineLearningNotebooks GitHub for instructions.

當您建立工作區自動 (如果它們也出現些許可用),會加入下列的 Azure 資源:When you create a workspace the following Azure resources are added automatically (if they're regionally available):

注意

如同其他 Azure 服務,Machine Learning 也有其相關的特定限制和配額。As with other Azure services, certain limits and quotas are associated with Machine Learning. 深入了解配額及如何要求更多配額。Learn about quotas and how to request more.

必要條件Prerequisites

若要建立工作區,您將需要 Azure 訂用帳戶。To create a workspace, you need an Azure subscription. 如果您沒有 Azure 訂用帳戶,請在開始前先建立一個免費帳戶。If you don’t have an Azure subscription, create a free account before you begin. 立即試用免費或付費版本的 Azure Machine Learning 服務Try the free or paid version of Azure Machine Learning service today.

Azure 入口網站Azure portal

  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. 在搜尋列中輸入 Machine LearningIn the search bar, enter Machine Learning. 選取 Machine Learning Service 工作區的搜尋結果。Select the Machine Learning service workspace search result.

    搜尋工作區

  4. 在 [ML 服務工作區] 窗格中選取 [建立] 來開始操作。In the ML service workspace pane, select Create to begin.

    建立按鈕

  5. 在 [ML 服務工作區] 窗格中,設定您的工作區。In the ML service workspace pane, configure your workspace.

    欄位Field 說明Description
    工作區名稱Workspace name 輸入可識別您工作區的唯一名稱。Enter a unique name that identifies your workspace. 在此範例中,我們使用 docs-wsIn 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 holds related resources for an Azure solution. 在此範例中,我們使用 docs-amlIn 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. 若要開始執行建立程序,請選取 [檢閱 + 建立] 。To start the creation process, select Review + Create.

    建立

  7. 檢閱工作區設定。Review your workspace configuration. 如果正確,請選取 [建立] 。If it is correct, select Create. 建立工作區可能需要一些時間。It can take a few moments to create the workspace.

    建立

  8. 若要檢查部署狀態,請選取工具列上的通知圖示 (鈴鐺) 。To check on the status of the deployment, select the Notifications icon, bell, on the toolbar.

  9. 程序完成後,會出現部署成功訊息。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.

    工作區建立狀態

無論其建立方式,您可以檢視您的工作區中Azure 入口網站No matter how it was created, you can view your workspace in the Azure portal. 請參閱檢視工作區如需詳細資訊。See view a workspace for details.

Python SDKPython SDK

建立您工作區中使用 Python SDK。Create your workspace using the Python SDK. 首先,您要安裝 SDK。First you need to install the SDK.

重要

如果您使用 Azure Databricks 的 Azure 資料科學虛擬機器,請略過安裝 SDK。Skip installation of the SDK if you use an Azure Data Science Virtual Machine or Azure Databricks.

注意

使用下列指示來安裝和使用 SDK,透過您的本機電腦。Use these instructions to install and use the SDK from your local computer. 若要使用 Jupyter 的遠端虛擬機器上,設定遠端桌面或 X 終端機工作階段。To use Jupyter on a remote virtual machine, set up a remote desktop or X terminal session.

安裝 SDK 之前,我們建議您先建立獨立的 Python 環境。Before you install the SDK, we recommend that you create an isolated Python environment. 雖然本文使用 Miniconda,但您也可以使用已安裝的完整 AnacondaPython virtualenvAlthough this article uses Miniconda, you can also use full Anaconda installed or Python virtualenv.

這篇文章中的指示將會安裝執行快速入門和教學課程 runbook 所需的所有套件。The instructions in this article will install all the packages you need to run the quickstart and tutorial notebooks. 其他範例 Notebook 可能需要安裝其他元件。Other sample notebooks may require installation of additional components. 如需這些元件的詳細資訊,請參閱 安裝 適用於 Python 的 Azure Machine Learning SDKFor more information about these components, see Install the Azure Machine Learning SDK for Python.

安裝 MinicondaInstall Miniconda

下載並安裝 MinicondaDownload and install Miniconda. 選取 Python 3.7 版進行安裝。Select the Python 3.7 version to install. 請勿選取 Python 2.x 版。Don't select the Python 2.x version.

建立獨立的 Python 環境Create an isolated Python environment

  1. 開啟 Anaconda 提示字元,然後建立名為新的 conda 環境myenv並安裝 Python 3.6.5。Open Anaconda Prompt , then create a new conda environment named myenv and install Python 3.6.5. Azure Machine Learning SDK 會使用 Python 3.5.2 或更新版本,但自動化機器學習元件在 Python 3.7 上無法完整運作。Azure Machine Learning SDK will work with Python 3.5.2 or later, but the automated machine learning components are not fully functional on Python 3.7. 建立環境可能需要幾分鐘的時間,因為需要下載元件和套件。It will take several minutes to create the environment while components and packages are downloaded.

    conda create -n myenv python=3.6.5
    
  2. 啟用環境。Activate the environment.

    conda activate myenv
    
  3. 啟用環境特定的 iPython 核心:Enable environment-specific ipython kernels:

    conda install notebook ipykernel
    

    然後建立核心:Then create the kernel:

    ipython kernel install --user
    

安裝 SDKInstall the SDK

  1. 在已啟動的 conda 環境中,安裝 Machine Learning SDK 的核心元件和 Jupyter Notebook 功能。In the activated conda environment, install the core components of the Machine Learning SDK with Jupyter notebook capabilities. 完成安裝需要幾分鐘的時間,視您的電腦組態而定。The installation takes a few minutes to finish based on the configuration of your machine.

    pip install --upgrade azureml-sdk[notebooks]
    
  2. 若要在 Azure Machine Learning 教學課程中使用此環境,請安裝這些套件。To use this environment for the Azure Machine Learning tutorials, install these packages.

    conda install -y cython matplotlib pandas
    
  3. 若要在 Azure Machine Learning 教學課程中使用此環境,請安裝自動化機器學習元件。To use this environment for the Azure Machine Learning tutorials, install the automated machine learning components.

    pip install --upgrade azureml-sdk[automl]
    

重要

在某些命令列工具中,您可能需要加上引號,如下所示:In some command-line tools, you might need to add quotation marks as follows:

  • 'azureml-sdk[notebooks]''azureml-sdk[notebooks]'
  • 'azureml-sdk[automl]''azureml-sdk[automl]'

使用 SDK 建立工作區Create a workspace with the SDK

使用 Python SDK 在 Jupyter Notebook 中建立您的工作區。Create your workspace in a Jupyter Notebook using the Python SDK.

  1. 建立並/或切換至您要在快速入門和教學課程中使用的目錄。Create and/or cd to the directory you want to use for the quickstart and tutorials.

  2. 若要啟動 Jupyter Notebook,請輸入下列命令:To launch Jupyter Notebook, enter this command:

    jupyter notebook
    
  3. 在瀏覽器視窗中,使用預設 Python 3 核心建立新的 Notebook。In the browser window, create a new notebook by using the default Python 3 kernel.

  4. 若要顯示 SDK 版本,請在 Notebook 資料格中輸入並執行下列 Python 程式碼:To display the SDK version, enter and then execute the following Python code in a notebook cell:

    import azureml.core
    print(azureml.core.VERSION)
    
  5. Azure 入口網站的訂用帳戶清單中尋找 <azure-subscription-id> 參數的值。Find a value for the <azure-subscription-id> parameter in the subscriptions list in the Azure portal. 使用您在其中是擁有者或參與者角色的任何訂用帳戶。Use any subscription in which your role is owner or contributor. 如需有關角色的詳細資訊,請參閱 < 管理的存取權的 Azure Machine Learning 工作區文章。For more information on roles, see Manage access to an Azure Machine Learning workspace article.

    from azureml.core import Workspace
    ws = Workspace.create(name='myworkspace',
                          subscription_id='<azure-subscription-id>', 
                          resource_group='myresourcegroup',
                          create_resource_group=True,
                          location='eastus2' 
                         )
    

    當您執行程式碼時,系統可能會提示您登入 Azure 帳戶。When you execute the code, you might be prompted to sign into your Azure account. 登入之後,會在本機快取驗證權杖。After you sign in, the authentication token is cached locally.

  6. 若要檢視工作區詳細資料,例如相關聯的儲存體、容器登錄和金鑰保存庫,請輸入下列程式碼:To view the workspace details, such as associated storage, container registry, and key vault, enter the following code:

    ws.get_details()
    

寫入組態檔Write a configuration file

將組態檔中的工作區詳細資料儲存到目前的目錄。Save the details of your workspace in a configuration file to the current directory. 這個檔案稱為 .azureml/config.jsonThis file is called .azureml/config.json.

此工作區組態檔可讓您稍後輕鬆地載入相同的工作區。This workspace configuration file makes it easy to load the same workspace later. 您可以將它與其他 notebook 和相同的目錄或子目錄,使用程式碼中的指令碼ws=Workspace.from_config()You can load it with other notebooks and scripts in the same directory or a subdirectory using the code ws=Workspace.from_config() .

# Create the configuration file.
ws.write_config()

# Use this code to load the workspace from 
# other scripts and notebooks in this directory.
# ws = Workspace.from_config()

write_config() API 呼叫會在目前的目錄中建立組態檔。This write_config() API call creates the configuration file in the current directory. .Azureml/config.json檔案包含下列:The .azureml/config.json file contains the following:

{
    "subscription_id": "<azure-subscription-id>",
    "resource_group": "myresourcegroup",
    "workspace_name": "myworkspace"
}

提示

若要使用您的工作區中的 Python 指令碼或位於另一個目錄中的 Jupyter Notebook,請將這個檔案複製到該目錄。To use your workspace in Python scripts or Jupyter Notebooks located in other directories, copy this file to that directory. 檔案可以在相同的目錄中,命名的子目錄 .azureml,或父目錄中。The file can be in the same directory, a subdirectory named .azureml, or in a parent directory.

Resource manager 範本Resource manager template

若要使用範本建立工作區,請參閱使用範本建立 Azure Machine Learning 服務工作區To create a workspace with a template, see Create an Azure Machine Learning service workspace by using a template

命令列介面Command-line interface

若要使用 CLI 建立工作區,請參閱使用 Azure Machine Learning 服務的 CLI 擴充功能To create a workspace with the CLI, see Use the CLI extension for Azure Machine Learning service.

清除資源Clean up resources

重要

您所建立的資源可用來作為其他 Azure Machine Learning 服務教學課程和操作說明文章的先決條件。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.

後續步驟Next steps