📜 ⬆️ ⬇️

Get started with Azure Machine Learning using the Python SDK

This article will use the Azure Machine Learning SDK for Python 3 to create and use the Azure Machine Learning workspace . This workspace is the core unit in the cloud for experimenting, learning, and deploying machine learning models using Azure Machine Learning.




You will begin by setting up your own Python environment and the Jupyter Notebook server. For information about starting without installation, see the article Quick Start Guide. Get started with the Azure Machine Learning Service using the Azure portal .


In this quick start guide you will:



You create a workspace and its configuration file that you can use as necessary components for working with other manuals and articles with Machine Learning instructions. As with other Azure services, the Azure Machine Learning service has certain limitations and quotas. Learn more about quotas and how to send requests for additional quotas.


The following Azure resources are automatically added to the workspace if they are available in your region:



Note


The code in this article requires an SDK for Azure Machine Learning 1.0.2 or later. The code has been tested with version 1.0.8.


If you do not already have an Azure subscription, create a free Azure account before you begin. Try a free or paid version of Azure Machine Learning .


Installing the SDK


Important!


Skip this section if you are using a Virtual Machine to process and analyze Azure or Azure Databricks data.


  • Virtual machines for processing and analyzing Azure data created after September 27, 2018 are shipped with the Python SDK already installed.
  • For Azure Databricks, perform the Databricks installation steps instead .


Before installing the SDK, it is recommended that you first create an isolated Python environment. Although Miniconda is used in this article, you can also use the fully installed Anaconda or Python virtualenv tool.


Install miniconda


Download and install Miniconda . Select Python 3.7 or later to install. Do not choose the version of Python 2.x.


Creating a Python sandbox


  1. Open a command window, then create a conda environment called myenv and install Python 3.6. The Azure Machine Learning SDK will work with Python 3.5.2 or later, but the automatic machine learning components are not fully functional in Python 3.7.


    conda create -n myenv -y Python=3.6 
  2. Activate the environment.


     conda activate myenv 

Installing the SDK


  1. In the conda activated environment, install the core components of the Azure Machine Learning SDK with the capabilities of the Jupyter notebook. Installation takes several minutes depending on the configuration of the computer.


      pip install --upgrade azureml-sdk[notebooks] 
  2. Install a Jupyter Notebook server in the conda environment.


     conda install -y nb_conda 
  3. To use this environment for Azure Machine Learning tutorials, install the following packages.


     conda install -y cython matplotlib pandas 
  4. To use this environment for Azure Machine Learning tutorials, install automatic machine learning components.


     pip install --upgrade azureml-sdk[automl] 

Creating a workspace


Create a workspace in Jupyter Notebook using the Python SDK.


  1. Create a directory that you want to use for quick reference and tutorials, or go to it.

  2. To run Jupyter Notebook, enter this command:


     jupyter notebook 
  3. In the browser window, create a notebook using the standard Python 3 kernel.

  4. To view the SDK version, enter the following Python code in the cell of the notebook and execute it.


     import azureml.core print(azureml.core.VERSION) 
  5. Find the value for <azure-subscription-id> in the list of subscriptions in the Azure portal . Use any subscription in which you are granted the role of owner or member.


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

    When executing the code, you may be asked to sign in to your Azure account. When you log in, the authentication token will be cached locally.

  6. To view information about the workspace, such as associated storage, container registry, and keystore, enter the following code.


     ws.get_details() 


Write configuration file


Save the workspace information in a configuration file in the current directory. This file is called aml_config \ config.json .


This workspace configuration file simplifies further loading of the same workspace. You can download it using other notebooks and scripts in the same directory or subdirectory.


 # 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() 

This write_config() API call allows you to create a configuration file in the current directory. The config.json file contains the following:


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

Use the workspace


Run code that uses the base SDK APIs to track several experimental runs.


  1. Create an experiment in the workspace.
  2. Enter one value into the experiment.
  3. Enter 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 registered results


After completing the run, test run information can be viewed on the Azure portal. To display the location URL with the last run results, use the following code.


 print(run.get_portal_url()) 

Use the link to view the logged values ​​in the Azure portal in a browser.


Registered values ​​on the Azure portal


Resource cleanup


Important!


Created resources can be used as necessary components when working with other Azure Machine Learning guides.


If you do not plan to use the resources created in this article, delete them so that no fee is charged.


 ws.delete(delete_dependent_resources=True) 

Additional Information


In this article, you have created resources for experimenting and deploying models. In addition, you ran the code in a notebook and studied the execution log from this code in your workspace in the cloud.


Manual Learning Image Classification Model


You can also study more complex examples on GitHub .


')

Source: https://habr.com/ru/post/442132/


All Articles