設定 Azure Machine Learning 的開發環境Configure a development environment for Azure Machine Learning

在本文中,您將瞭解如何設定開發環境來與 Azure Machine Learning 搭配使用。In this article, you learn how to configure a development environment to work with Azure Machine Learning. Azure Machine Learning 與平臺無關。Azure Machine Learning is platform agnostic. 您的開發環境唯一的硬性需求是 Python 3。The only hard requirement for your development environment is Python 3. 也建議使用隔離的環境,例如 Anaconda 或 Virtualenv。An isolated environment like Anaconda or Virtualenv is also recommended.

下表顯示本文涵蓋的每個開發環境,以及優缺點。The following table shows each development environment covered in this article, along with pros and cons.

環境Environment 優點Pros 缺點Cons
以雲端為基礎的筆記本 VMCloud-based notebook VM 最簡單的入門方式。Easiest way to get started. 整個 SDK 已安裝在您的工作區 VM 中,且筆記本教學課程已預先複製並可供執行。The entire SDK is already installed in your workspace VM, and notebook tutorials are pre-cloned and ready to run. 缺少開發環境和相依性的控制權。Lack of control over your development environment and dependencies. Linux VM 所產生的額外成本(VM 可以在未使用時停止,以避免費用)。Additional cost incurred for Linux VM (VM can be stopped when not in use to avoid charges). 請參閱定價詳細資料See pricing details.
本機環境Local environment 完全控制您的開發環境和相依性。Full control of your development environment and dependencies. 使用您選擇的任何組建工具、環境或 IDE 來執行。Run with any build tool, environment, or IDE of your choice. 開始使用較長的時間。Takes longer to get started. 必須安裝必要的 SDK 套件,如果您還沒有環境,也必須安裝它。Necessary SDK packages must be installed, and an environment must also be installed if you don't already have one.
Azure DatabricksAzure Databricks 適用于在可調整的 Apache Spark 平臺上執行大規模的機器學習工作流程。Ideal for running large-scale intensive machine learning workflows on the scalable Apache Spark platform. 適用于實驗性機器學習服務的大材小用,或較小規模的實驗和工作流程。Overkill for experimental machine learning, or smaller-scale experiments and workflows. Azure Databricks 所產生的額外成本。Additional cost incurred for Azure Databricks. 請參閱定價詳細資料See pricing details.
資料科學虛擬機器(DSVM)The Data Science Virtual Machine (DSVM) 類似于雲端式筆記本 VM (已預先安裝 Python 和 SDK),但已預先安裝其他常用的資料科學和機器學習工具。Similar to the cloud-based notebook VM (Python and the SDK are pre-installed), but with additional popular data science and machine learning tools pre-installed. 易於調整,並與其他自訂工具和工作流程結合。Easy to scale and combine with other custom tools and workflows. 相較于以雲端為基礎的筆記本 VM,更慢的使用者入門體驗。A slower getting started experience compared to the cloud-based notebook VM.

本文也提供下列工具的其他使用秘訣:This article also provides additional usage tips for the following tools:

  • Jupyter Notebook:如果您已經在使用 Jupyter Notebook,則 SDK 有一些您應該安裝的附加功能。Jupyter Notebooks: If you're already using the Jupyter Notebook, the SDK has some extras that you should install.

  • Visual Studio Code:如果您使用 Visual Studio Code, Azure Machine Learning 延伸模組包含 Python 的廣泛語言支援,以及可讓您使用 Azure Machine Learning 服務更方便且更有效率的功能。Visual Studio Code: If you use Visual Studio Code, the Azure Machine Learning extension includes extensive language support for Python as well as features to make working with the Azure Machine Learning service much more convenient and productive.

必要條件Prerequisites

Azure Machine Learning 工作區。An Azure Machine Learning workspace. 若要建立工作區,請參閱建立 Azure Machine Learning 工作區To create the workspace, see Create an Azure Machine Learning workspace. 您只需要工作區,就能開始使用自己的雲端式筆記本伺服器DSVMAzure DatabricksA workspace is all you need to get started with your own cloud-based notebook server, a DSVM, or Azure Databricks.

若要為您的本機電腦安裝 SDK 環境, Jupyter Notebook serverVisual Studio Code您也需要:To install the SDK environment for your local computer, Jupyter Notebook server or Visual Studio Code you also need:

  • 可能是AnacondaMiniconda套件管理員。Either the Anaconda or Miniconda package manager.

  • 在 Linux 或 macOS 上,您需要 bash 殼層。On Linux or macOS, you need the bash shell.

    提示

    如果您使用的是 Linux 或 macOS 並使用 bash 以外的殼層 (例如,zsh),則在執行一些命令時可能會收到錯誤。If you're on Linux or macOS and use a shell other than bash (for example, zsh) you might receive errors when you run some commands. 若要解決此問題,請使用 bash 命令啟動新的 bash 殼層,並在其中執行命令。To work around this problem, use the bash command to start a new bash shell and run the commands there.

  • 在 Windows 上,您需要命令提示字元或 Anaconda 提示字元 (由 Anaconda 和 Miniconda 安裝)。On Windows, you need the command prompt or Anaconda prompt (installed by Anaconda and Miniconda).

您自己的雲端式筆記本 VMYour own cloud-based notebook VM

筆記本虛擬機器(預覽)是安全的雲端式 Azure 工作站,可為數據科學家提供 Jupyter 筆記本伺服器、JupyterLab 和完整備妥的 ML 環境。The notebook virtual machine (preview) is a secure, cloud-based Azure workstation that provides data scientists with a Jupyter notebook server, JupyterLab, and a fully prepared ML environment.

筆記本 VM 是:The notebook VM is:

  • 安全Secure. 由於 VM 和筆記本存取是使用 HTTPS 來保護, 而且預設 Azure Active Directory, 因此 IT 專業人員可以輕鬆地強制執行單一登入和其他安全性功能, 例如多重要素驗證。Since VM and notebook access is secured with HTTPS and Azure Active Directory by default, IT Pros can easily enforce single sign-on and other security features such as multi-factor authentication.

  • 預先設定。Preconfigured. 這個完整備妥的 Python ML 環境會從熱門的 IaaS 資料科學 VM 繪製其歷史, 並包括:This fully prepared Python ML environment draws its pedigree from the popular IaaS Data Science VM and includes:

    • Azure ML Python SDK (最新)Azure ML Python SDK (latest)
    • 自動設定以使用您的工作區Automatic configuration to work with your workspace
    • Jupyter 筆記本伺服器A Jupyter notebook server
    • JupyterLab 筆記本 IDEJupyterLab notebook IDE
    • 預先設定的 GPU 驅動程式Preconfigured GPU drivers
    • 深度學習架構的選取範圍A selection of deep learning frameworks

    如果您要進入程式碼,VM 會包含可協助您探索及瞭解如何使用 Azure Machine Learning 的教學課程和範例。If you are into code, the VM includes tutorials and samples to help you explore and learn how to use Azure Machine Learning. 範例筆記本會儲存在工作區的 Azure Blob 儲存體帳戶中, 讓它們可在 Vm 之間共用。The sample notebooks are stored in the Azure Blob Storage account of your workspace making them shareable across VMs. 執行時, 他們也可以存取您工作區的資料存放區和計算資源。When run, they also have access to the data stores and compute resources of your workspace.

  • 簡單設定:從您的 Azure Machine Learning 工作區中隨時建立一個。Simple setup: Create one anytime from within your Azure Machine Learning workspace. 只提供名稱,並指定 Azure VM 類型。Provide just a name and specify an Azure VM type. 請在本教學課程中立即試用:設定環境和工作區Try it now with this Tutorial: Setup environment and workspace.

  • 可自訂Customizable. 在受管理且安全的 VM 供應專案中, 您可以保留硬體功能的完整存取權, 並根據您的需求進行自訂。While a managed and secure VM offering, you retain full access to the hardware capabilities and customize it to your heart’s desire. 例如, 您可以快速建立最新的 NVidia V100 供電 VM, 以執行 novel 類神經網路架構的逐步偵錯工具。For example, quickly create the latest NVidia V100 powered VM to perform step-by-step debugging of novel Neural Network architecture.

若要停止產生筆記本 VM 費用, 請停止筆記本 vmTo stop incurring notebook VM charges, stop the notebook VM.

資料科學虛擬機器Data Science Virtual Machine

DSVM 是自訂的虛擬機器 (VM) 映像。The DSVM is a customized virtual machine (VM) image. 它是針對使用下列項目預先設定的資料科學工作而設計:It's designed for data science work that's pre-configured with:

  • TensorFlow、PyTorch、Scikit-learn、XGBoost 及 Azure Machine Learning SDK 等套件Packages such as TensorFlow, PyTorch, Scikit-learn, XGBoost, and the Azure Machine Learning SDK
  • Spark 獨立版和 Drill 等常用的資料科學工具Popular data science tools such as Spark Standalone and Drill
  • Azure CLI、AzCopy 及儲存體總管等 Azure 工具Azure tools such as the Azure CLI, AzCopy, and Storage Explorer
  • Visual Studio Code 和 PyCharm 等整合式開發環境 (IDE)Integrated development environments (IDEs) such as Visual Studio Code and PyCharm
  • Jupyter Notebook 伺服器Jupyter Notebook Server

Azure Machine Learning SDK 適用於 Ubuntu 或 Windows版本的 DSVM。The Azure Machine Learning SDK works on either the Ubuntu or Windows version of the DSVM. 但如果您也打算使用 DSVM 作為計算目標,則僅支援 Ubuntu。But if you plan to use the DSVM as a compute target as well, only Ubuntu is supported.

若要使用 DSVM 做為開發環境:To use the DSVM as a development environment:

  1. 在下列其中一個環境中建立 DSVM:Create a DSVM in either of the following environments:

    • Azure 入口網站:The Azure portal:

    • Azure CLI:The Azure CLI:

      重要

      • 使用 Azure CLI 時,您必須先使用 az login 命令來登入您的 Azure 訂用帳戶。When you use the Azure CLI, you must first sign in to your Azure subscription by using the az login command.

      • 使用此步驟中的命令時,您必須提供資源群組名稱、VM 名稱、使用者名稱及密碼。When you use the commands in this step, you must provide a resource group name, a name for the VM, a username, and a password.

      • 若要建立「Ubuntu 資料科學虛擬機器」,請使用下列命令:To create an Ubuntu Data Science Virtual Machine, use the following command:

        # create a Ubuntu DSVM in your resource group
        # note you need to be at least a contributor to the resource group in order to execute this command successfully
        # If you need to create a new resource group use: "az group create --name YOUR-RESOURCE-GROUP-NAME --location YOUR-REGION (For example: westus2)"
        az vm create --resource-group YOUR-RESOURCE-GROUP-NAME --name YOUR-VM-NAME --image microsoft-dsvm:linux-data-science-vm-ubuntu:linuxdsvmubuntu:latest --admin-username YOUR-USERNAME --admin-password YOUR-PASSWORD --generate-ssh-keys --authentication-type password
        
      • 若要建立「Windows 資料科學虛擬機器」,請使用下列命令:To create a Windows Data Science Virtual Machine, use the following command:

        # create a Windows Server 2016 DSVM in your resource group
        # note you need to be at least a contributor to the resource group in order to execute this command successfully
        az vm create --resource-group YOUR-RESOURCE-GROUP-NAME --name YOUR-VM-NAME --image microsoft-dsvm:dsvm-windows:server-2016:latest --admin-username YOUR-USERNAME --admin-password YOUR-PASSWORD --authentication-type password
        
  2. Azure Machine Learning SDK 已安裝在 DSVM 上。The Azure Machine Learning SDK is already installed on the DSVM. 若要使用包含該 SDK 的 Conda 環境,請使用下列命令之一:To use the Conda environment that contains the SDK, use one of the following commands:

    • Ubuntu DSVM:For Ubuntu DSVM:

      conda activate py36
      
    • Windows DSVM:For Windows DSVM:

      conda activate AzureML
      
  3. 若要確認您是否可以存取 SDK 並檢查版本,請使用下列 Python 程式碼:To verify that you can access the SDK and check the version, use the following Python code:

    import azureml.core
    print(azureml.core.VERSION)
    
  4. 若要將 DSVM 設定為使用您的 Azure Machine Learning 工作區,請參閱建立工作區設定檔一節。To configure the DSVM to use your Azure Machine Learning workspace, see the Create a workspace configuration file section.

如需詳細資訊,請參閱資料科學虛擬機器For more information, see Data Science Virtual Machines.

本機電腦Local computer

當您使用本機電腦(也可能是遠端虛擬機器)時,請建立 Anaconda 環境並安裝 SDK。When you're using a local computer (which might also be a remote virtual machine), create an Anaconda environment and install the SDK. 以下為範例:Here's an example:

  1. 如果您還沒有Anaconda (Python 3.7 版本),請下載並安裝。Download and install Anaconda (Python 3.7 version) if you don't already have it.

  2. 開啟 Anaconda 提示字元, 並使用下列命令建立環境:Open an Anaconda prompt and create an environment with the following commands:

    執行下列命令來建立環境。Run the following command to create the environment.

    conda create -n myenv python=3.6.5
    

    然後啟用環境。Then activate the environment.

    conda activate myenv
    

    這個範例會使用 python 3.6.5 建立環境, 但是可以選擇任何特定的 subversions。This example creates an environment using python 3.6.5, but any specific subversions can be chosen. SDK 相容性可能無法保證某些主要版本 (建議使用 3.5 +), 如果遇到錯誤, 建議您在 Anaconda 環境中嘗試不同的版本/subversion。SDK compatibility may not be guaranteed with certain major versions (3.5+ is recommended), and it's recommended to try a different version/subversion in your Anaconda environment if you run into errors. 建立環境可能需要幾分鐘的時間,因為需要下載元件和套件。It will take several minutes to create the environment while components and packages are downloaded.

  3. 在您的新環境中執行下列命令, 以啟用環境特定的 ipython 核心。Run the following commands in your new environment to enable environment-specific ipython kernels. 這可確保在 Anaconda 環境中使用 Jupyter 筆記本時, 預期的核心和套件匯入行為:This will ensure expected kernel and package import behavior when working with Jupyter Notebooks within Anaconda environments:

    conda install notebook ipykernel
    

    然後執行下列命令來建立核心:Then run the following command to create the kernel:

    ipython kernel install --user
    
  4. 使用下列命令來安裝套件:Use the following commands to install packages:

    此命令會使用筆記本和automl額外專案來安裝基底 Azure Machine Learning SDK。This command installs the base Azure Machine Learning SDK with notebook and automl extras. 額外automl的是大型安裝, 如果您不想要執行自動化機器學習實驗, 可以從括弧中移除。The automl extra is a large install, and can be removed from the brackets if you don't intend to run automated machine learning experiments. 額外automl的也包含 Azure Machine Learning 資料準備 SDK, 預設為相依性。The automl extra also includes the Azure Machine Learning Data Prep SDK by default as a dependency.

    pip install azureml-sdk[notebooks,automl]
    

    注意

    • 如果顯示訊息表示無法解除安裝 PyYAML ,請改用下列命令:If you get a message that PyYAML can't be uninstalled, use the following command instead:

      pip install --upgrade azureml-sdk[notebooks,automl] --ignore-installed PyYAML

    • 從 macOS Catalina 開始,zsh (Z shell)是預設的登入命令介面和互動式 shell。Starting with macOS Catalina, zsh (Z shell) is the default login shell and interactive shell. 在 zsh 中,使用下列命令,將括弧加上\"" (反斜線):In zsh, use the following command which escapes brackets with "\" (backslash):

      pip install --upgrade azureml-sdk\[notebooks,automl\]

    安裝 SDK 需要幾分鐘的時間。It will take several minutes to install the SDK. 如需安裝選項的詳細資訊,請參閱安裝指南For more information on installation options, see the install guide.

  5. 為您的機器學習實驗安裝其他套件。Install other packages for your machine learning experimentation.

    使用下列其中一個命令, 並將 <新的封裝 > 取代為您要安裝的套件。Use either of the following commands and replace <new package> with the package you want to install. 透過安裝套件conda install時, 套件必須是目前通道的一部分 (可以在 Anaconda Cloud 中新增新的通道)。Installing packages via conda install requires that the package is part of the current channels (new channels can be added in Anaconda Cloud).

    conda install <new package>
    

    或者, 您也可以透過安裝pip套件。Alternatively, you can install packages via pip.

    pip install <new package>
    

Jupyter NotebookJupyter Notebooks

Jupyter Notebook 是 Jupyter 專案的一部分。Jupyter Notebooks are part of the Jupyter Project. 它們提供互動式程式碼撰寫體驗,讓您用來建立混合即時程式碼與敘述文字和圖形的文件。They provide an interactive coding experience where you create documents that mix live code with narrative text and graphics. Jupyter Notebook 也是與其他人共用結果的好方法,因為您可以將程式碼區段的輸出儲存在文件中。Jupyter Notebooks are also a great way to share your results with others, because you can save the output of your code sections in the document. 您可以在各種不同的平台上安裝 Jupyter Notebook。You can install Jupyter Notebooks on a variety of platforms.

[本機電腦] 區段中的程式會安裝在 Anaconda 環境中執行 Jupyter 筆記本所需的元件。The procedure in the Local computer section installs necessary components for running Jupyter Notebooks in an Anaconda environment.

若要在您的 Jupyter Notebook 環境中啟用這些元件:To enable these components in your Jupyter Notebook environment:

  1. 開啟 Anaconda 提示字元並啟用您的環境。Open an Anaconda prompt and activate your environment.

    conda activate myenv
    
  2. 複製一組範例筆記本的 GitHub 存放庫Clone the GitHub repository for a set of sample notebooks.

    git clone https://github.com/Azure/MachineLearningNotebooks.git
    
  3. 使用下列命令啟動 Jupyter Notebook 伺服器:Launch the Jupyter Notebook server with the following command:

    jupyter notebook
    
  4. 若要確認 Jupyter Notebook 可以使用 SDK, 請建立的筆記本, 選取 [ Python 3 ] 做為您的核心, 然後在 [筆記本] 儲存格中執行下列命令:To verify that Jupyter Notebook can use the SDK, create a New notebook, select Python 3 as your kernel, and then run the following command in a notebook cell:

    import azureml.core
    azureml.core.VERSION
    
  5. 如果您在匯入模組和接收ModuleNotFoundError時遇到問題, 請在 [筆記本] 儲存格中執行下列程式碼, 以確保您的 Jupyter 核心已連接到您環境的正確路徑。If you encounter issues importing modules and receive a ModuleNotFoundError, ensure your Jupyter kernel is connected to the correct path for your environment by running the following code in a Notebook cell.

    import sys
    sys.path
    
  6. 若要設定 Jupyter Notebook 使用您的 Azure Machine Learning 工作區,請移至建立工作區設定檔一節。To configure the Jupyter Notebook to use your Azure Machine Learning workspace, go to the Create a workspace configuration file section.

Visual Studio CodeVisual Studio Code

Visual Studio Code 是一個非常熱門的跨平臺程式碼編輯器,可透過Visual Studio marketplace中提供的延伸模組,支援一組豐富的程式設計語言和工具。Visual Studio Code is a very popular cross platform code editor that supports an extensive set of programming languages and tools through extensions available in the Visual Studio marketplace. Azure Machine Learning 延伸模組會安裝python 延伸模組,以便在所有類型的 python 環境中撰寫程式碼(虛擬、Anaconda 等)。The Azure Machine Learning extension installs the Python extension for coding in all types of Python environments (virtual, Anaconda, etc.). 此外,它還提供便利的功能來處理 Azure Machine Learning 資源,並在不離開 Visual Studio Code 的情況下執行 Azure Machine Learning 實驗。In addition, it provides convenience features for working with Azure Machine Learning resources and running Azure Machine Learning experiments all without leaving Visual Studio Code.

若要使用 Visual Studio Code 進行開發:To use Visual Studio Code for development:

  1. 安裝 Visual Studio Code 的 Azure Machine Learning 延伸模組,請參閱Azure Machine LearningInstall the Azure Machine Learning extension for Visual Studio Code, see Azure Machine Learning.

    如需詳細資訊,請參閱使用適用於 Visual Studio Code 的 Azure Machine LearningFor more information, see Use Azure Machine Learning for Visual Studio Code.

  2. 瞭解如何將 Visual Studio Code 用於任何類型的 Python 開發,請參閱在 VSCode 中開始使用 pythonLearn how to use Visual Studio Code for any type of Python development, see Get started with Python in VSCode.

    • 若要選取包含 SDK 的 SDK Python 環境,請開啟 [VS Code],然後選取 [Ctrl + Shift + P (Linux 和 Windows)] 或 [命令 + Shift + P (Mac)]。To select the SDK Python environment containing the SDK, open VS Code, and then select Ctrl+Shift+P (Linux and Windows) or Command+Shift+P (Mac).

      • __命令__選擇區隨即開啟。The Command Palette opens.
    • 輸入 Python:選取 [ 解譯器],然後選取適當的環境Enter Python: Select Interpreter, and then select the appropriate environment

  3. 若要驗證您是否可以使用 SDK,請建立新的 Python 檔案(. .py),其中包含下列程式碼:To validate that you can use the SDK, create a new Python file (.py) that contains the following code:

    #%%
    import azureml.core
    azureml.core.VERSION
    

    按一下 [執行資料格] CodeLens,或直接按 shift enter 來執行此程式碼。Run this code by clicking the "Run cell" CodeLens or simply press shift-enter.

Azure DatabricksAzure Databricks

Azure Databricks 是 Azure 雲端中以 Apache Spark 為基礎的環境。Azure Databricks is an Apache Spark-based environment in the Azure cloud. 它提供以 CPU 或 GPU 為基礎的計算叢集的共同作業筆記本型環境。It provides a collaborative Notebook-based environment with CPU or GPU-based compute cluster.

Azure Databricks 如何與 Azure Machine Learning 搭配運作:How Azure Databricks works with Azure Machine Learning:

  • 您可以使用 Spark MLlib 來定型模型, 並從 Azure Databricks 內將模型部署至 ACI/AKS。You can train a model using Spark MLlib and deploy the model to ACI/AKS from within Azure Databricks.
  • 您也可以在具有 Azure Databricks 的特殊 Azure ML SDK 中, 使用自動化機器學習功能。You can also use automated machine learning capabilities in a special Azure ML SDK with Azure Databricks.
  • 您可以使用 Azure Databricks 做為來自Azure Machine Learning 管線的計算目標。You can use Azure Databricks as a compute target from an Azure Machine Learning pipeline.

設定 Databricks 叢集Set up your Databricks cluster

建立Databricks叢集。Create a Databricks cluster. 只有當您在 Databricks 上安裝 SDK 以進行自動化機器學習時, 才適用某些設定。Some settings apply only if you install the SDK for automated machine learning on Databricks. 建立叢集需要幾分鐘的時間。It will take few minutes to create the cluster.

請使用下列設定:Use these settings:

設定Setting 適用於Applies to Value
叢集名稱Cluster name 永遠always yourclusternameyourclustername
Databricks 執行階段Databricks Runtime 永遠always 任何非 ML 執行時間(非 ML 4.x、5.x)Any non-ML runtime (non-ML 4.x, 5.x)
Python 版本Python version 永遠always 33
背景工作Workers 永遠always 2 個以上2 or higher
背景工作節點 VM 類型Worker node VM types
(判斷並行反覆運算的最大數目)(determines max # of concurrent iterations)
自動化 MLAutomated ML
only
建議使用已記憶體最佳化的 VMMemory optimized VM preferred
啟用自動調整Enable Autoscaling 自動化 MLAutomated ML
only
取消選取Uncheck

請靜候至叢集運作,再繼續操作。Wait until the cluster is running before proceeding further.

將正確的 SDK 安裝到 Databricks 程式庫Install the correct SDK into a Databricks library

叢集執行之後, 請建立程式庫, 以將適當的 Azure Machine Learning SDK 套件附加至您的叢集。Once the cluster is running, create a library to attach the appropriate Azure Machine Learning SDK package to your cluster.

  1. 只選擇一個選項 (不支援其他 SDK 安裝)Choose only one option (no other SDK installation are supported)

    SDK 套件 額外專案SDK package extras SourceSource PyPi 名稱      PyPi Name      
    針對 DatabricksFor Databricks 上傳 Python Egg 或 PyPIUpload Python Egg or PyPI azureml-sdk[databricks]azureml-sdk[databricks]
    針對 Databricks-with-For Databricks -with-
    自動化 ML 功能automated ML capabilities
    上傳 Python Egg 或 PyPIUpload Python Egg or PyPI azureml-sdk[automl_databricks]azureml-sdk[automl_databricks]

    警告

    無法安裝其他 SDK 額外專案。No other SDK extras can be installed. 選擇上述選項 [databricks] 或 [automl_databricks] 其中之一。Choose only one of the preceding options [databricks] or [automl_databricks].

    • 請勿選取 [自動附加至所有叢集]。Do not select Attach automatically to all clusters.
    • 選取 附加旁您的叢集名稱。Select Attach next to your cluster name.
  2. 監視錯誤直到狀態變更為 [已附加], 這可能需要幾分鐘的時間。Monitor for errors until status changes to Attached, which may take several minutes. 如果此步驟失敗:If this step fails:

    嘗試重新開機您的叢集:Try restarting your cluster by:

    1. 在左窗格中,選取 [叢集]。In the left pane, select Clusters.
    2. 請選取表格中您的叢集名稱。In the table, select your cluster name.
    3. 在 [程式庫] 索引標籤上,選取 [重新啟動]。On the Libraries tab, select Restart.

    也請考慮:Also consider:

    • 在 AutoML config 中,使用 Azure Databricks 新增下列參數:In AutoML config, when using Azure Databricks add the following parameters:
      1. max_concurrent_iterations是根據叢集中的背景工作節點數目。max_concurrent_iterations is based on number of worker nodes in your cluster.
      2. spark_context=sc是以預設 spark 內容為基礎。spark_context=sc is based on the default spark context.
    • 或者, 如果您有舊的 SDK 版本, 請從叢集的已安裝的程式庫中取消選取它, 並移至垃圾桶。Or, if you have an old SDK version, deselect it from cluster’s installed libs and move to trash. 安裝新版 SDK,並重新啟動叢集。Install the new SDK version and restart the cluster. 如果重新開機後發生問題,請卸離並重新附加您的叢集。If there is an issue after the restart, detach and reattach your cluster.

如果安裝成功, 則匯入的程式庫看起來應該像下列其中一項:If install was successful, the imported library should look like one of these:

Sdk for Databricks, 不含 自動化機器學習服務 Azure Machine Learning sdk for DatabricksSDK for Databricks without automated machine learning Azure Machine Learning SDK for Databricks

SDK for Databricks搭配自動化機器學習服務 sdk, 並在 Databricks 上安裝自動化機器學習服務SDK for Databricks WITH automated machine learning SDK with automated machine learning installed on Databricks

開始探索Start exploring

試試看:Try it out:

建立工作區組態檔Create a workspace configuration file

工作區設定檔是一種 JSON 檔案,可告知 SDK 如何與您的 Azure Machine Learning 工作區進行通訊。The workspace configuration file is a JSON file that tells the SDK how to communicate with your Azure Machine Learning workspace. 檔案名稱為 config.json,其格式如下:The file is named config.json, and it has the following format:

{
    "subscription_id": "<subscription-id>",
    "resource_group": "<resource-group>",
    "workspace_name": "<workspace-name>"
}

這個 JSON 檔案必須位於包含您的 Python 指令碼或 Jupyter Notebook 的目錄結構中。This JSON file must be in the directory structure that contains your Python scripts or Jupyter Notebooks. 可以位於相同的目錄,名為 aml_config 的子目錄,或位於父目錄。It can be in the same directory, a subdirectory named .azureml, or in a parent directory.

要使用程式碼中的此檔案,請使用 ws=Workspace.from_config()To use this file from your code, use ws=Workspace.from_config(). 此程式碼會從檔案載入資訊,並連接到您的工作區。This code loads the information from the file and connects to your workspace.

您可以透過三種方式建立組態檔:You can create the configuration file in three ways:

  • 使用write_config :寫入config.xml檔案。Use ws.write_config: to write a config.json file. 此檔案包含您工作區的組態資訊。The file contains the configuration information for your workspace. 您可以將此 config.json 下載或複製到其他開發環境。You can download or copy the config.json to other development environments.

  • 下載檔案:在 Azure 入口網站中,從您工作區的 [概觀] 區段選取 [下載 config.json]。Download the file: In the Azure portal, select Download config.json from the Overview section of your workspace.

    Azure 入口網站

  • 以程式設計方式建立檔案:在下列程式碼片段中,您可以提供訂用帳戶識別碼、資源群組和工作區名稱來連線到工作區。Create the file programmatically: In the following code snippet, you connect to a workspace by providing the subscription ID, resource group, and workspace name. 接著,它會將工作區組態儲存至檔案:It then saves the workspace configuration to the file:

    from azureml.core import Workspace
    
    subscription_id = '<subscription-id>'
    resource_group  = '<resource-group>'
    workspace_name  = '<workspace-name>'
    
    try:
        ws = Workspace(subscription_id = subscription_id, resource_group = resource_group, workspace_name = workspace_name)
        ws.write_config()
        print('Library configuration succeeded')
    except:
        print('Workspace not found')
    

    此程式碼會將設定檔寫入azureml/config json檔案。This code writes the configuration file to the .azureml/config.json file.

後續步驟Next steps