Rana Maninder Singh
Lesson 7 of 8Microsoft Azure for Data & AI

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

ResourceLink
PreviousPipelines
NextCapstone
Prerequisitesaz6, mlops1
Time~55 minutes

What you will learn

By the end of this lesson you will be able to:

  1. Train a tiny classifier locally with a pinned scikit-learn.
  2. Register the model as a name + version + metrics dict (the registry idea).
  3. Score one row through a predict function that mimics an endpoint.
  4. Refuse to start compute when a budget flag is off.
  5. Stop Azure ML compute (not just the studio tab) when the job ends.
  6. 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)

  1. Resource group → Create → Azure Machine Learning. Workspace name, region, storage (often created for you — that storage also bills).
  2. Open Studio. Compute → Compute instances → create the smallest CPU size → Start only when you will train.
  3. Jobs / Notebooks: run the train script. Note the run id.
  4. Models → Register from the job output (name + version).
  5. Endpoints → Real-time → deploy the registered version to the smallest SKU. Test once.
  6. 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) == 6

Expected 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 REGISTRY

Expected output:

churn-logit:1
1

Demo 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:

1

Guided 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
start

Independent 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) == 2

Expected output:

2

Common 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-after tag on the workspace and a same-day teardown checklist.

Snapshot — checked September 2026

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.