internalsGet Pro

Module 01 · Lesson 1 of 10Free

Introduction to machine learning engineering

Level
Beginner
Topic
Machine learning fundamentals
Reading time
12 min

When you finish this page you can

  1. Explain why a model that works once in a notebook is not yet something a business can use every week.
  2. Name the parts of an ML system around the model, and what goes wrong when each one is missing.
  3. Decide whether a problem should start with a hand-written rule or a model, and what would change that choice.
  4. Show, with a short pandas snippet, that the same code gives a different answer when the data changes.
0:00 / 5:58
Show transcript

0:00 Meet Farah, an ML engineer at Kartly, our example online store. Joseph runs the growth team, and he worries about churn. Churn means customers who stop buying and never come back. Each Monday, his team can email a hundred rupee voucher to the customers most likely to leave. But which twenty thousand customers should get it? Farah builds a model in a notebook. A notebook is a page where code and its results sit together. A model is a program that reads what a customer has done, and says how likely they are to leave. On last year’s orders, it works well. It picks out most of the customers who later stopped buying. Joseph is pleased. He asks, can we have this list every Monday from now on? Quick question. Next Monday, Farah runs her notebook again, with no code changes. Does Joseph get the same list? No. Some quiet customers bought again. Others went quiet. The data moved, so the list moved. One good answer is not enough. Joseph needs a fresh, trustworthy list every week. So here’s what this lesson asks. What does it take to turn a model that worked once into something a business can rely on?

0:58 Ordinary software follows rules a person writes. A developer types: no order in sixty days, flag the customer. The program obeys until someone edits the code. Farah’s model works differently. Nobody typed its rules. Instead, a program studied past customers. It looked at who stopped buying, and what they did first. That step is called training. Then the trained model is used on today’s customers. That is called inference. So three things decide what Joseph gets on Monday. First, the code. If Farah fixes a bug, the list changes. Second, this week’s data. Customers placed new orders, so the list changes. Third, the training data. If Farah retrains on newer orders, the model’s rules themselves change. Ordinary tests check the first one. Nothing in ordinary software checks the other two. That gap is what ML engineering fills.

1:40 Google researchers looked at real ML systems. They found the model code is a small slice. Most of the system is the machinery around it. That machinery is costly to maintain. Google’s own guide agrees. Most of your problems will be engineering problems. Here is what Joseph’s Monday list needs around Farah’s model. First, data. A fresh copy of the orders every week. Second, features. These turn raw orders into numbers the model can read, like days since the last order. Third, a training job. It trains the model from code, not by hand. Fourth, a model store. It keeps each model with its version. Fifth, a scoring job. It runs every Monday and delivers twenty thousand names. Sixth, monitoring. It watches inputs and results, and asks for retraining. Take away any one part and something breaks. Without fresh data, the model scores last month’s customers. Without a model store, nobody knows which model made last week’s list. Without a scoring job, Joseph waits for Farah to press Run. None of this is unusual. Data engineers already build pipelines, and backend engineers build scheduled jobs. What’s new is that data decides how the system behaves. So each part must keep data, code and model in step. So what is ML engineering? It’s training and running models on a company’s own data, shipping them, and keeping them useful after launch. Farah’s week is mostly those six parts, not the model. Two nearby jobs share the load. Data engineers make sure clean, fresh data arrives. AI engineers build product features on a model someone else trained. Joseph’s list needs Kartly’s own order history, so this one is ML engineering.

3:05 Before Farah builds any of those parts, there is a more basic question. How should Kartly pick the customers for Monday’s voucher? Option one: a hand-written rule. No order in the last sixty days. It ships today, and anyone can read it. But it only notices a customer after two quiet months. By then, many have started buying elsewhere. Option two: build the full ML system now. It could notice early signs, like smaller baskets. But it needs all six parts before the first email. And nobody can tell whether it beats something simpler. Option three: ship the rule first. Measure how it does. Then build a model that has to beat it. This one wins. Joseph gets his list this week. And the rule’s results become the score to beat. A rule used this way is a baseline. It’s the simple answer a model must beat to earn its cost. Google’s guide agrees. Don’t be afraid to launch without machine learning. What Kartly should do depends on the evidence. Say the rule already catches most leavers in time. Then Kartly stops there. Say the model catches them weeks sooner. Then it earns its six parts. Here’s one more choice. The voucher goes out weekly. So one batch job on Monday morning, scoring everyone, is enough. Scoring a customer each time they open the app would add servers and gain nothing.

4:08 Suppose the model beats the rule, and Farah builds all six parts. The code is bug-free. Even so, it can fail, because the world the data describes keeps changing. To find out, Farah holds back a thousand flagged customers from each email. Sixty days later, she counts how many really stopped buying. Before the festival sale, forty percent of them really did stop buying. The list was mostly right. After the sale, just ten percent did. Why? Many loyal customers placed one big festival order, then paused. They do that every year. But the model had learned from ordinary months that a pause means leaving. So it flagged them. That money goes to the wrong people. Most of the twenty thousand vouchers go to customers who were coming back anyway. That’s up to eighteen lakh rupees a week. Meanwhile, the real leavers are crowded off the list. These are the lesson’s example numbers, not measurements. Notice what didn’t change. The code. The world moved, and the model didn’t. And there’s a delay. Farah only finds out who really left sixty days later. That’s too slow. So monitoring watches the inputs too. Say a lot more customers suddenly have long pauses. That’s a warning, weeks before any results. Then Farah retrains the model on recent orders. Spotting this shift early is a core part of ML engineering.

5:18 Let’s recap. One: a model that worked once needs a whole system around it before a business can rely on it. Data, features, training, a model store, a scheduled job and monitoring. Two: the list depends on three things. The code, the training data and today’s data. So it can get worse without any code change. Three: ML engineers run models trained on the company’s own data. Four: begin with a plain rule. Build a model only if it beats the rule by enough to pay for its parts. Five: models go stale as the world changes. Watch what goes in, not only what comes out. Farah’s model learned that a pause means leaving, and nobody typed that rule. How does a program find rules like that from data? That’s next, in What machine learning is.

Farah’s model works once, on her laptop

is our example online store. Its ML team works with a sample of the store’s data that fits in a free : about 1 million orders from 200,000 customers, across 50,000 products.

Joseph leads Kartly’s growth team. He worries about : customers who stop buying and never come back. Every Monday, his team could email a ₹100 voucher to the customers most likely to leave. But which 20,000 customers should get it?

Farah, an ML engineer, builds a for this in a notebook: a document where code and its results sit together, run one step at a time. A model here is a program that takes what a customer has done and returns how likely they are to leave. On last year’s orders, her model picks out most of the customers who later stopped buying.

Joseph is pleased. “Great. Can my team have the list every Monday from now on?”

Check yourselfAnswer in your head first, then reveal
Farah runs her notebook again next Monday without changing a line of code. Does Joseph get the same list of customers?Show answerHide answer
No. During the week some quiet customers bought again and others went quiet, so the data changed and the list changed with it. In an ML system the output depends on the data as much as on the code.

The notebook gave one good answer, once. Joseph needs a fresh, trustworthy list every week, for months. So the question this lesson answers is: what does it take to turn a model that worked once into something a business can rely on every week?

A model’s behaviour comes from data, not only code

In ordinary software, a person writes the rules. A developer types “if no order in 60 days, flag the customer”, and the program does exactly that until someone edits the code.

Farah’s model is different. Nobody typed its rules. A program found them by studying past customers: who stopped buying, and what they did before they stopped. That step is called . Using the trained model on today’s customers is called . What machine learning is shows how rules are learned from data.

In ordinary software a person writes the rule. In an ML system training finds the rules in last year’s orders, so new training data changes them too.

So three things decide what Joseph gets on Monday:

What changes Example at Kartly Does the list change?
The code Farah fixes a bug in how she counts orders Yes
This week’s data 30,000 customers placed orders since last Monday Yes
The training data Farah on orders up to last month Yes: the model’s rules themselves change

Ordinary tests check the first row. Nothing in ordinary software checks the other two. That is the gap ML engineering fills.

The model is the smallest part of the system

A team at Google described real in which the model code is only a small part. The rest is the machinery around it, and that machinery carries large ongoing maintenance costs.1 Google’s guide to ML engineering puts it plainly: most problems you will face are engineering problems.2

Here is what Joseph’s Monday list needs around Farah’s model:

Joseph’s Monday list needs six parts around the model. Farah’s notebook built only the model.
Part What it does for the churn list What goes wrong without it
Data Pulls a fresh copy of orders every week The model scores customers on last month’s orders
Features Turns raw orders into numbers the model reads Training and Monday’s run compute them differently, and scores are quietly wrong
Training job Retrains the model from code, not by hand Nobody can rebuild the model if Farah’s laptop dies
Model store Keeps each model with its version and the data it learned from Nobody can say which model made last week’s list
Scoring job Runs every Monday and delivers 20,000 names Joseph waits for Farah to press Run
Monitoring Watches inputs and results, and asks for retraining The list goes stale and nobody notices

None of these parts is unusual on its own. Data engineers build pipelines; backend engineers build scheduled jobs. The ML part is that the data decides the behaviour, so every part has to keep data, code and model in step. The ML lifecycle walks through these stages in order.

What an ML engineer does

is training, shipping and running models that learn from a company’s own data, and keeping them useful after launch. Farah’s week is mostly the table above, not the model. ML engineering roles describes the job and its variants in detail.

Two neighbouring jobs share the work:

  • Data engineers build the pipelines that deliver clean, fresh data. At Kartly, Farah’s data step reads from them. Working with analysts, data scientists and ML teams covers that handoff.
  • AI engineers build product features on a model someone else trained, usually a language model behind an API. Introduction to AI engineering explains that job. Joseph’s churn list needs Kartly’s own order history, so it is ML engineering, not .

Before Farah builds any of the six parts, she has a more basic question to answer.

Start with a rule, then make the model beat it

How should Kartly pick the 20,000 customers who get Monday’s voucher?

A hand-written rule: no order in the last 60 days.

Ships today and anyone can read it. But it only notices a customer after two quiet months, when many have already started buying elsewhere.

Build the full ML system now.

Can notice early signs, such as smaller baskets or longer gaps than usual. But it needs all six parts before the first email, and nobody can tell whether it beats something simpler.

Why this choice

Google’s guide gives the same advice: don’t be afraid to launch without machine learning, and keep the first model simple while you get the infrastructure right.2 The rule is a : the simple answer any model must beat to earn its cost. Baselines shows how to build one.

The choice changes with the evidence. If the rule already finds most leavers early enough, Kartly stops there, and When not to use machine learning covers that case. If the model finds them weeks earlier, it pays for its six parts.

One smaller choice follows from the voucher email. It goes out once a week, so a batch job that scores everyone on Monday morning is enough. Scoring each customer the moment they open the app would add servers and speed limits for no gain.

Try it yourself

This snippet runs in a free Colab or Kaggle notebook, or on a laptop with NumPy and pandas, in a second. It makes up 200,000 Kartly customers, applies the 60-day rule, then moves time forward one week:

Python
import numpy as np
import pandas as pd

rng = np.random.default_rng(42)
n = 200_000  # customers in Kartly's notebook sample (made-up data)

customers = pd.DataFrame({
    "customer_id": np.arange(n),
    "days_since_last_order": rng.exponential(scale=30, size=n).round().astype(int),
})


def win_back_list(df: pd.DataFrame) -> set[int]:
    """The baseline rule: no order in the last 60 days."""
    quiet = df["days_since_last_order"] > 60
    return set(df.loc[quiet, "customer_id"].tolist())


monday_1 = win_back_list(customers)

# One week later: every gap grows by 7 days,
# except for about 15% of customers who ordered again this week.
next_week = customers.copy()
next_week["days_since_last_order"] += 7
ordered = rng.random(n) < 0.15
next_week.loc[ordered, "days_since_last_order"] = rng.integers(0, 7, size=ordered.sum())

monday_2 = win_back_list(next_week)

print("Monday 1:", len(monday_1))
print("Monday 2:", len(monday_2))
print("Joined:", len(monday_2 - monday_1), "Left:", len(monday_1 - monday_2))

Expect about 26,600 names on the first Monday and about 28,600 on the second. About 6,000 customers join the list and about 4,000 leave it. These are expected values worked out from the made-up data, not measured results; your run will differ by a few hundred.

What to look for: not one line of code changed between the two Mondays, yet about one name in five on the new list wasn’t there a week before. With a trained model, the rules themselves would also move each time Farah retrains.

When the world changes, the model goes stale

Say the model beats the rule, and Farah builds all six parts. The code is bug-free. It can still fail, because the data describes a world that keeps changing. The Google paper names changes in the external world as one of the main risks of ML systems.1

To check the list, Farah keeps 1,000 flagged customers out of each email. Sixty days later, she counts how many of them really stopped buying.

Before the festival sale

400 of 1,000 held-out customers stop buying = 40%

The list mostly finds real leavers. Joseph’s 20,000 vouchers go mostly to the right people.

After the festival sale

100 of 1,000 = 10%

Many loyal customers made one big festival order, then paused, as they do every year. The model learned from last year’s ordinary months that a pause means leaving, so it flags them.

What the stale list costs

18,000 of 20,000 vouchers × ₹100 = up to ₹18 lakh a week

That money goes to customers who were coming back anyway, if they all use the voucher. Meanwhile the real leavers are crowded off the list.

All numbers in these steps are this lesson’s scenario, not measurements.

The code never changed. The world did, and the 60-day wait to see who really left means monitoring has to watch the inputs too.

Notice the delay. Farah learns who really left only 60 days later. So monitoring also watches the inputs: a sudden jump in customers with long pauses is a warning weeks before the results arrive. When it fires, she retrains on recent orders. Catching that , and fixing it before Joseph’s budget is spent, is a core part of ML engineering.

Where this shows up

Farah’s model learned that a pause means leaving, without anyone typing that rule. How a program finds rules like that from data is the next lesson.

Common mistakes

  • Calling the notebook result done. One good run on last year’s data says nothing about next Monday. The six parts around the model are the product.
  • Skipping the baseline. Without the 60-day rule’s results, nobody can tell whether the model is worth its cost.
  • Testing only the code. Most ML failures come from changed data, not changed code. Check the data each run, too.
  • Waiting for results to notice a problem. If you learn who left only 60 days later, watch the inputs in the meantime.

Check your understanding

Check yourselfAnswer in your head first, then reveal
Kartly’s model list got worse in November, but nobody changed the code since August. Where should Farah look first?Show answerHide answer
At the data. Customer behaviour shifted, here after the festival sale, so the model’s learned rules no longer fit. Not the code: an unchanged program can still give worse answers when the world it learned from changes.
Check yourselfAnswer in your head first, then reveal
Farah’s model is 10% better than the 60-day rule on last year’s data. Is that enough to build all six parts?Show answerHide answer
Not on its own. Compare what the gain is worth, in vouchers that reach real leavers, with the cost of building and running the six parts. A small gain may not pay for them, and then the rule wins.
Check yourselfAnswer in your head first, then reveal
Farah’s laptop breaks. The model file is gone. Which part of the system should have prevented this hurting Joseph?Show answerHide answer
The training job and the model store. If training runs from code on shared data, and each model is stored with its version, anyone can rebuild or reload it. A model that exists only in one notebook is a single point of failure.
Check yourselfAnswer in your head first, then reveal
Joseph asks for the churn score to update every time a customer opens the app. The voucher email still goes out once a week. What would that change buy him?Show answerHide answer
Nothing for this email. The list is only used on Monday, so a weekly batch job gives the same result. Real-time scoring would add servers and speed limits, and pays off only if something acts on the score inside the app.

Summary

  1. Turning a model that worked once into something a business relies on means building the system around it: data, features, training, a model store, a scheduled job and monitoring.
  2. An ML system’s output depends on its code, its training data and today’s data, so it can change, or get worse, with no code change.
  3. ML engineering builds and runs models trained on a company’s own data. Data engineers feed it; AI engineers build on models someone else trained.
  4. Start with a simple rule as the baseline, and build a model only if it beats the rule by enough to pay for its parts.
  5. Models go stale when the world changes. Watch the inputs as well as the results, because results can arrive weeks late.

Report a mistake

Tell us what’s wrong in this lesson and we’ll fix it.