Get started with Azure Machine Learning for Visual Studio Code
In this article, you'll learn how to install the Azure Machine Learning for Visual Studio Code extension and create your first experiment with Azure Machine Learning service in Visual Studio Code (VS Code).
Use the Azure Machine Learning extension in Visual Studio code to use the Azure Machine Learning service to prep your data, train, and test machine learning models on local and remote compute targets, deploy those models and track custom metrics and experiments.
If you don’t have an Azure subscription, create a free account before you begin. Try the free or paid version of Azure Machine Learning service today.
Visual Studio Code must be installed. VS Code is a lightweight but powerful source code editor that runs on your desktop. It comes with built-in support for Python and more. Learn how to install VS Code.
Install the Azure Machine Learning for VS Code extension
When you install the Azure Machine Learning extension, two more extensions are automatically installed (if you have internet access). They are the Azure Account extension and the Microsoft Python extension
To work with Azure Machine Learning, we need to turn VS Code into a Python IDE. Working with Python in Visual Studio Code, requires the Microsoft Python extension, which gets installed with the Azure Machine Learning extension automatically. The extension makes VS Code an excellent IDE, and works on any operating system with a variety of Python interpreters. It leverages all of VS Code's power to provide auto complete and IntelliSense, linting, debugging, and unit testing, along with the ability to easily switch between Python environments, including virtual and conda environments. Check out this walk-through of editing, running, and debugging Python code, see the Python Hello World Tutorial
To install the Azure Machine Learning extension:
Launch VS Code.
In a browser, visit: Azure Machine Learning for Visual Studio Code (Preview) extension
In that web page, click Install.
In the extension tab, click Install.
A welcome tab opens in VS Code for the extension and the Azure symbol is added to activity bar.
In the dialog box, click Sign In and follow the onscreen prompt to authenticate with Azure.
The Azure Account extension, which was installed along with the Azure Machine Learning for VS Code extension, helps you authenticate with your Azure account. See the list of commands in the Azure Account extension page.
Check out the IntelliCode extension for VS Code (preview). IntelliCode provides a set of AI-assisted capabilities for IntelliSense in Python, such as inferring the most relevant auto-completions based on the current code context.
Azure ML SDK Installation
Make sure that Python 3.5 or greater is installed and recognized by VS Code. If you install it now, then restart VS Code and select a Python interpreter using instructions at https://code.visualstudio.com/docs/python/python-tutorial.
In the integrated terminal window, specify the Python interpreter to use or you can hit Enter to use your default Python interpreter.
In the bottom-right corner of the window, a notification will appear indicating that the Azure ML SDK is being automatically installed. A local private Python environment is created that has the Visual Studio Code prerequisites for working with Azure Machine Learning.
Get started with Azure Machine Learning
Before you start training and deploying machine learning models using VS Code, you need to create an Azure Machine Learning service workspace in the cloud to contain your models and resources. Learn how to create one and create your first experiment in that workspace.
Click the Azure icon in the Visual Studio Code activity bar. The Azure Machine Learning sidebar appears.
Right-click your Azure subscription and select Create Workspace. A list appears. In the animated image, the subscription name is 'Free Trial' and the workspace is 'TeamWorkspace'.
Select an existing resource group from the list or create a new one using the wizard in the Command Palette.
In the field, type a unique and clear name for your new workspace. In the screenshots, the workspace is named 'TeamWorkspace'.
Hit enter and the new workspace is created. It appears in the tree below the subscription name.
Right-click on the Experiment node and choose Create Experiment from the context menu. Experiments keep track of your runs using Azure Machine Learning.
In the field, enter a name your experiment. In the screenshots, the experiment is named 'MNIST'.
Hit enter and the new experiment is created. It appears in the tree below the workspace name.
You can right-click on an Experiment in a Workspace and select 'Set as Active Experiment'. The 'Active' experiment is the experiment you are currently using and your open folder in VS Code will be linked to this experiment in the cloud. This folder should contain your local Python scripts.
Now each of your experiment runs with your experiment, so all of your key metrics will be stored in the experiment history and the models you train will get automatically uploaded to Azure Machine Learning and stored with your experiment metrics and logs.
Use keyboard shortcuts
Like most of VS Code, the Azure Machine Learning features in VS Code are accessible from the keyboard. The most important key combination to know is Ctrl+Shift+P, which brings up the Command Palette. From here, you have access to all of the functionality of VS Code, including keyboard shortcuts for the most common operations.
You can now use Visual Studio Code to work with Azure Machine Learning.
We'd love to hear your thoughts. Choose the type you'd like to provide:
Our feedback system is built on GitHub Issues. Read more on our blog.