Complete Azure Machine Learning Tutorial: End-to-End ML on Azure
Azure Machine Learning is a cloud-based platform for building, training, and deploying machine learning models. It provides a comprehensive MLOps environment with tools for the entire ML lifecycle.
Why Azure Machine Learning?
Key Benefits:- Unified platform: Complete ML lifecycle management
- AutoML: Automated machine learning capabilities
- Enterprise-ready: Security, compliance, and governance
- Flexible compute: From notebooks to GPU clusters
- Integration: Seamless Azure ecosystem connectivity
- Workspaces
- Compute instances and clusters
- Datastores and datasets
- Experiments and runs
- Models and endpoints
Prerequisites
pip install azure-ai-ml azure-identity
Azure CLI
az login
az extension add -n ml
Quick Start
1. Create Workspace
from azure.ai.ml import MLClient
from azure.identity import DefaultAzureCredential
from azure.ai.ml.entities import Workspace
Authenticate
credential = DefaultAzureCredential()
Create workspace
workspace = Workspace(
name="my-ml-workspace",
location="eastus",
displayname="ML Workspace",
description="Azure ML workspace for ML projects"
)
Create ML client
mlclient = MLClient(
credential=credential,
subscriptionid="your-subscription-id",
resourcegroupname="my-resource-group"
)
Create workspace
mlclient.workspaces.begincreateorupdate(workspace).result()
print(f"Workspace created: {workspace.name}")
2. Connect to Existing Workspace
from azure.ai.ml import MLClient
from azure.identity import DefaultAzureCredential
mlclient = MLClient(
credential=DefaultAzureCredential(),
subscriptionid="your-subscription-id",
resourcegroupname="my-resource-group",
workspacename="my-ml-workspace"
)
print(f"Connected to workspace: {mlclient.workspacename}")
Compute Resources
1. Create Compute Instance
from azure.ai.ml.entities import ComputeInstance
computeinstance = ComputeInstance(
name="my-compute-instance",
size="StandardDS3v2",
idletimebeforeshutdownminutes=60
)
mlclient.compute.begincreateorupdate(computeinstance).result()
print("Compute instance created")
2. Create Compute Cluster
from azure.ai.ml.entities import AmlCompute
computecluster = AmlCompute(
name="cpu-cluster",
type="amlcompute",
size="StandardDS3v2",
mininstances=0,
maxinstances=4,
idletimebeforescaledown=120
)
mlclient.compute.begincreateorupdate(computecluster).result()
print("Compute cluster created")
3. GPU Cluster
gpucluster = AmlCompute(
name="gpu-cluster",
type="amlcompute",
size="Standard
NC6",
mininstances=0,
maxinstances=2,
idletimebeforescaledown=300
)
mlclient.compute.begincreateorupdate(gpucluster).result()
Data Management
1. Register Datastore
from azure.ai.ml.entities import AzureBlobDatastore
datastore = AzureBlobDatastore(
name="my-blob-datastore",
accountname="mystorageaccount",
containername="ml-data",
credentials={
"accountkey": "your-account-key"
}
)
mlclient.datastores.createorupdate(datastore)
print("Datastore registered")
2. Create Dataset
from azure.ai.ml.entities import Data
from azure.ai.ml.constants import AssetTypes
File dataset
filedata = Data(
name="training-data",