Advent of 2022, Day 10 – Connecting to client using Python SDK namespaces
This article is originally published at https://tomaztsql.wordpress.com
In the series of Azure Machine Learning posts:
- Dec 01: What is Azure Machine Learning?
- Dec 02: Creating Azure Machine Learning Workspace
- Dec 03: Understanding Azure Machine Learning Studio
- Dec 04: Getting data to Azure Machine Learning workspace
- Dec 05: Creating compute and cluster instances in Azure Machine Learning
- Dec 06: Environments in Azure Machine Learning
- Dec 07: Introduction to Azure CLI and Python SDK
- Dec 08: Python SDK namespaces for workspace, experiments and models
- Dec 09: Python SDK namespaces for environment, and pipelines
Let’s continue to explore the power of SDK and the namespaces. And we will look into namespace that will help you connect to Azure ML resources with Python SDK.
Connecting with Visual Studio Code
For this demonstration, I will create a new notebook (IPynb) and write a couple of Python code. And you can click on “Edit in VS Code (preview)”
You will be redirected to Visual studio code. From there you will be able to write, validate and execute your Python code.
At the bottom of your VS Code, you will find the connection to Azure and the name of the workspace. In order to do so, you will need to have VS Code installed with some additional extensions: Azure extension, Python and Jupyter extensions and Python packages for accessing the storage or other service.
Everything you write in VS Code will be automatically saved in the workspace in Azure ML. This is because you are opening the entire workspace locally through VS Code and all changes are stored on the cloud.
Using AzureML namespace in Python code
The next step is to have a simple Python code execute the authentication to Azure ML Workspace and to start using the assets in Azue ML.
By using a Jupyter notebook on a local machine, I can access the assets to Azure ML workspace and run all the commands on a local machine.
# !pip install azure-ai-ml
# !pip install azureml-core
# authorization
from azureml.core.authentication import InteractiveLoginAuthentication
interactive_auth = InteractiveLoginAuthentication(tenant_id="xxxxxxxx-tenantID-xxxxxxxxxx", force=True)
from azureml.core import Workspace
subscription_id = "xxxxxxx-subscriptionID-xxxxxxxxxxx"
resource_group = "RG_AML_Blogpost2022"
workspace_name = "AML_Blogpost2022"
ws = Workspace(subscription_id, resource_group, workspace_name)
# check the workspace
ws.get_details()
#list all the experiments
from azureml.core.experiment import Experiment
list_experiments = Experiment.list(ws)
list_experiments
If want to use a Token for authorisation or any other authorisation? Here is a comprehensive list of all possible authentications is here in Jupyter notebook.
Tomorrow, we will look into using Pipelines.
Compete set of code, documents, notebooks, and all of the materials will be available at the Github repository: https://github.com/tomaztk/Azure-Machine-Learning
Happy Advent of 2022!
Thanks for visiting r-craft.org
This article is originally published at https://tomaztsql.wordpress.com
Please visit source website for post related comments.