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

Capstone: a small end-to-end pipeline inside a cost guard

Lesson opener

In one line: Copy, transform, train, register, and score locally, and refuse any step when the cost guard is off.

Why it matters: A Chennai pilot that "only forgot to delete compute" is how Azure labs get banned internally.

Before this lesson: Azure Machine Learning.

Before you start

ResourceLink
PreviousAzure Machine Learning
Next—
Prerequisitesaz7
Time~55 minutes

What you will learn

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

  1. Guard every step with a single cost_guard_ok flag.
  2. Copy and transform a tiny orders table.
  3. Train and register a model version from those rows.
  4. Score one new city row through the stand-in endpoint.
  5. Print a teardown list: trigger, compute, endpoint, group.
  6. Keep the whole path off live Azure so the only bill is zero.

The path (still one resource group)

Real Azure would be: storage (raw) → Data Factory copy+transform → Azure SQL or lake (silver) → Azure ML train/register/endpoint. This capstone runs that sequence in process. If you later recreate it in the portal, use one resource group, the smallest SKUs, no trigger until debug is green, and delete the group the same day.

Cost. Do not create a VM, a compute cluster, or an online endpoint for this exercise. If you ignore that and create them anyway, delete the resource group before you log off. The cost guard below is the habit; the group delete is the brake.

Portal click-path if you recreate it later

  1. Create rg-azure-capstone-YYYYMMDD in your lab subscription.
  2. Storage (hierarchical namespace if you want folders) → container raw → upload ten rows.
  3. Optional: Azure SQL or stay on the lake for silver.
  4. Data Factory: copy raw → silver, then stop. No trigger.
  5. Azure ML: train on the laptop (this script), register the file, do not deploy an online endpoint unless finance approved it.
  6. Delete the resource group. Confirm Cost analysis the next morning.

Demo 1 — Cost guard

def guarded(step: str, cost_guard_ok: bool) -> str:
    if not cost_guard_ok:
        return f"refuse:{step}"
    return f"run:{step}"

print(guarded("copy", False))
print(guarded("copy", True))
assert guarded("train", False) == "refuse:train"

Expected output:

refuse:copy
run:copy

Demo 2 — Copy, transform, train, register, score

from sklearn.linear_model import LogisticRegression

def run_pipeline(cost_guard_ok: bool) -> dict:
    if not cost_guard_ok:
        return {"status": "refused"}
    raw = [
        {"city": " bengaluru", "tickets": 3, "churned": 1},
        {"city": "pune", "tickets": 0, "churned": 0},
        {"city": "mumbai", "tickets": 4, "churned": 1},
        {"city": "pune", "tickets": 1, "churned": 0},
        {"city": "jaipur", "tickets": 5, "churned": 1},
        {"city": "noida", "tickets": 0, "churned": 0},
    ]
    silver = []
    for row in raw:
        silver.append(
            {
                "city": row["city"].strip().title(),
                "tickets": int(row["tickets"]),
                "churned": int(row["churned"]),
            }
        )
    X = [[r["tickets"]] for r in silver]
    y = [r["churned"] for r in silver]
    model = LogisticRegression(max_iter=200, random_state=42)
    model.fit(X, y)
    registry = {"churn-logit:1": {"version": 1, "n": len(silver)}}
    label = int(model.predict([[4]])[0])
    return {
        "status": "ok",
        "rows": len(silver),
        "cities": sorted({r["city"] for r in silver}),
        "registered": "churn-logit:1",
        "score": label,
        "model_version": registry["churn-logit:1"]["version"],
    }

out = run_pipeline(True)
print(out["status"])
print(out["rows"])
print(out["registered"])
print(out["score"] in (0, 1))
assert out["rows"] == 6
assert "Bengaluru" in out["cities"]

Expected output:

ok
6
churn-logit:1
True

Demo 3 — Teardown list

def teardown() -> list[str]:
    return [
        "stop-or-delete-triggers",
        "stop-compute-and-endpoints",
        "delete-resource-group",
        "check-cost-analysis-next-day",
    ]

steps = teardown()
print(len(steps))
print(steps[0])
print(steps[2])
assert steps[-1].startswith("check-cost")

Expected output:

4
stop-or-delete-triggers
delete-resource-group

Guided practice: guard off

def run_pipeline(cost_guard_ok: bool) -> dict:
    if not cost_guard_ok:
        return {"status": "refused"}
    return {"status": "ok"}

print(run_pipeline(False)["status"])
assert run_pipeline(False)["status"] == "refused"

Expected output:

refused

Independent practice: city count

Deliverable: run the silver step and print how many distinct cities landed.

raw = [
    {"city": " bengaluru", "tickets": 3},
    {"city": "pune", "tickets": 0},
    {"city": "bengaluru", "tickets": 1},
]
cities = {row["city"].strip().title() for row in raw}
print(len(cities))
assert len(cities) == 2

Expected output:

2

Common mistake

The deliberate mistake

Symptom: the script is green on a laptop, then someone "just deploys the endpoint" for a demo and leaves it.

Diagnosis: the capstone succeeded locally; the bill is from an extra Azure resource.

Correction: delete the endpoint and the group. Re-run only the local script for the next demo.

Prevention: the cost guard is a flag on the ticket, not a comment in a notebook.

Snapshot — checked September 2026

Where this connects

What you can now do:

  • Run copy → transform → train → register → score behind a guard.
  • Recite the teardown list in order.
  • Keep the exercise off live compute.