Azure Machine Learning: train, register, deploy an endpoint
Lesson opener
In one line: Train a model, register a versioned artifact, then score through a function that stands in for an endpoint — compute is what bills.
Why it matters: A Gurugram demo that leaves a training cluster on overnight is a finance incident, not an ML incident.
Before this lesson: Pipelines and From notebook to script.
Before you start
What you will learn
By the end of this lesson you will be able to:
- Train a tiny classifier locally with a pinned scikit-learn.
- Register the model as a name + version + metrics dict (the registry idea).
- Score one row through a
predictfunction that mimics an endpoint. - Refuse to start compute when a budget flag is off.
- Stop Azure ML compute (not just the studio tab) when the job ends.
- Walk the portal/studio path for workspace, job, and endpoint in text.
Workspace, job, model, endpoint
Azure Machine Learning is a workspace that holds jobs (training runs), a model registry, and endpoints (real-time or batch). The studio is free to open. Compute clusters, compute instances, and online endpoints are the meters.
This lesson trains and "registers" offline. The registry is a Python dict. The endpoint is a function. That is the same sequence you later click in the studio.
WHY Register-then-deploy is how you know which bytes are live.
WHEN After a script already trains on a laptop (mlops1).
Cost. Creating a workspace is cheap; compute is not. A compute instance keeps billing until you Stop. An online endpoint keeps a scoring replica until you delete the endpoint. Jobs can leave clusters running. Stop compute, delete the endpoint, then delete the group. Closing the studio tab does nothing.
Portal click-path (text only)
- Resource group → Create → Azure Machine Learning. Workspace name, region, storage (often created for you — that storage also bills).
- Open Studio. Compute → Compute instances → create the smallest CPU size → Start only when you will train.
- Jobs / Notebooks: run the train script. Note the run id.
- Models → Register from the job output (name + version).
- Endpoints → Real-time → deploy the registered version to the smallest SKU. Test once.
- Teardown: Endpoints → delete → Compute → Stop and delete → delete workspace / group.
Demo 1 — Train a tiny model
Pin: scikit-learn==1.5.2 from docs/azure/requirements.txt.
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
X = [[2, 1], [4, 0], [10, 0], [3, 2], [12, 0], [1, 3]]
y = [1, 0, 0, 1, 0, 1]
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.33, random_state=42, stratify=y
)
model = LogisticRegression(max_iter=200, random_state=42)
model.fit(X_train, y_train)
acc = float(model.score(X_test, y_test))
print(round(acc, 2))
print(len(X_train), len(X_test))
assert len(X_train) + len(X_test) == 6Expected output:
1.0
4 2(The split is tiny; accuracy is 1.0 with this seed. The point is a fitted estimator, not a leaderboard.)
Demo 2 — Register a version
REGISTRY: dict[str, dict] = {}
def register(name: str, version: int, metrics: dict) -> str:
key = f"{name}:{version}"
if key in REGISTRY:
raise ValueError("version exists")
REGISTRY[key] = {"name": name, "version": version, "metrics": metrics}
return key
key = register("churn-logit", 1, {"accuracy": 1.0})
print(key)
print(REGISTRY[key]["version"])
assert "churn-logit:1" in REGISTRYExpected output:
churn-logit:1
1Demo 3 — Endpoint stand-in
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
X = [[2, 1], [4, 0], [10, 0], [3, 2], [12, 0], [1, 3]]
y = [1, 0, 0, 1, 0, 1]
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.33, random_state=42, stratify=y
)
model = LogisticRegression(max_iter=200, random_state=42)
model.fit(X_train, y_train)
def score_endpoint(model, features: list[float]) -> int:
pred = model.predict([features])
return int(pred[0])
label = score_endpoint(model, [2, 3])
print(label)
assert label in {0, 1}Expected output:
1Guided practice: refuse compute without budget
def may_start_compute(budget_ok: bool) -> str:
return "start" if budget_ok else "refuse-compute"
print(may_start_compute(False))
print(may_start_compute(True))
assert may_start_compute(False) == "refuse-compute"Expected output:
refuse-compute
startIndependent practice: next version
Deliverable: register version 2 and print the highest version for churn-logit.
REGISTRY: dict[str, dict] = {}
def register(name: str, version: int, metrics: dict) -> str:
key = f"{name}:{version}"
if key in REGISTRY:
raise ValueError("version exists")
REGISTRY[key] = {"name": name, "version": version, "metrics": metrics}
return key
register("churn-logit", 1, {"accuracy": 1.0})
register("churn-logit", 2, {"accuracy": 0.5})
versions = [v["version"] for k, v in REGISTRY.items() if v["name"] == "churn-logit"]
print(max(versions))
assert max(versions) == 2Expected output:
2Common mistake
The deliberate mistake
Symptom: studio is closed, Cost analysis still climbs.
Diagnosis: compute instance or online endpoint is still allocated.
Correction: Compute → Stop/Delete; Endpoints → Delete; then the group.
Prevention:
stop-aftertag on the workspace and a same-day teardown checklist.
Snapshot — checked September 2026
- Azure Machine Learning workspace, jobs, model registry, and managed endpoints are the current studio nouns (Microsoft Learn: Azure Machine Learning). SKU names for compute instances and online deployments change.
- Studio UX is free to browse; compute and endpoints bill. Check the compute blade, not the browser tab.
- Free-account credits can burn quickly on even a small cluster. Prefer local training (this lesson) unless the job cannot fit a laptop.
Where this connects
What you can now do:
- Train, register, score as three separate steps.
- Refuse compute when the budget flag is off.
- Tear down endpoint and compute, not just the tab.
Next lesson: Capstone. One small path that stays inside a cost guard.