Skip to content

Choose the learning task

  • Lesson 4
  • 60 min
  • Module 1: Understand machine learning

What you will be able to do

Choose the kind of task from the shape of the answer that the decision needs: a number, a class or a group. Or choose no model, when a rule, a lookup or a report gives the answer. The wrong kind of task produces predictions that nobody can act on.

NotebookDo this lesson in a notebookColab · Kaggle · GitHub

The notebook finds each kind of task in the real data: tickets per day, escalated or not, and customers without a label. It also runs a rule, a lookup and a report, and has the module practice with a check. Its setup cells install pandas and scikit-learn and download the practice data, so it needs no local setup. About 30 minutes.

Colab and Kaggle open your own copy. They need a free Google or Kaggle account. Stuck? See the solution notebook.

Before you startWhat to know and to have readyAbout 60 minutes

What you need to know

What you need on your computer (only for the local route; the notebook needs none of it)

The notebook was tested in Jupyter on macOS. It used Python 3.14.6, pandas 3.0.6, scikit-learn 1.9.1 and matplotlib 3.11.2.

A weather service gets four questions on the same morning. A farmer asks: “How many millimetres of rain will fall tomorrow?” A family that plans a picnic asks: “Will it rain tomorrow, yes or no?” A researcher asks: “Which days of the last ten years had similar weather?” And a reporter asks: “How much rain fell last May?”

The data is the same for all four: years of weather records. But the answers have different shapes. The farmer needs a number. The family needs a class: yes or no. The researcher needs groups, and nobody knows the right groups in advance. The reporter needs a fact from the past: it is already in the records, so nothing must be predicted.

Each shape needs a different method. If you build a yes-or-no model for the farmer, he still does not know how much water his fields get. If you build a model for the reporter, it can only add errors to a number that you can look up. The shape of the answer that someone needs decides the task. Choose it before you choose any model.

Larkfield’s team asks the same four kinds of question about its help desk:

  1. Omar plans staff: “How many tickets will arrive tomorrow?” The answer is a number, such as 26, 31 or 14. Past days have their real counts, so this is supervised learning with a number as the label: regression.
  2. Grace routes tickets: “Will this new ticket escalate within 72 hours?” The answer is one of two classes. Past tickets have the right answer in escalated_72h, so this is supervised learning with a class as the label: classification.
  3. Grace also asks: “Which customers are similar to each other?” The answer is groups, and nobody has written the right groups down. This is unsupervised learning: clustering.
  4. Omar asks for his report: “How many tickets escalated in April?” April is over, and the answer is in the data. You count it. No model: a report.
Question The answer looks like Learning Task
How many tickets will arrive tomorrow? A number: 26, 31, 14 Supervised Regression
Will this new ticket escalate within 72 hours? A class: yes or no Supervised Classification
Which customers are similar to each other? Groups that nobody has given Unsupervised Clustering
How many tickets escalated in April? A count of past tickets None No model: a report

You can find the task for any question with three questions, in this order. The diagram shows them.

  1. Is the answer already known, or does a known value give it exactly? Then no model is needed: count it, look it up, or write the rule.
  2. Do past examples have the right answer, a label? If not, you cannot learn a rule from features to an answer. You can only look for groups: clustering, and a person must judge the groups.
  3. If there is a label, what does the answer look like? A number means regression. A class means classification.
A decision flow. A question from the business leads to: is the answer already known, or does a known value give it exactly? Yes leads to No model: a report, a lookup or a rule. No leads to: do past examples have the right answer, a label? No leads to Clustering: groups that a person must judge. Yes leads to: what does the answer look like? A number leads to Regression, for example tickets tomorrow. A class leads to Classification, for example escalated, yes or no.
Three questions choose the task: is the answer already known, is there a label, and is the answer a number or a class.
Text description of the diagram

The flow starts with a question from the business. The first decision asks: is the answer already known, or does a known value give it exactly? If yes, the result is “No model”: a report, a lookup or a rule.

If no, the second decision asks: do past examples have the right answer, a label? If no, the result is “Clustering”: groups that a person must judge.

If yes, the third decision asks: what does the answer look like? A number leads to “Regression”, for example the number of tickets tomorrow. A class leads to “Classification”, for example escalated, yes or no.

The three tasks also differ in what a wrong answer means, and so in how you will measure them in Module 3:

Task The label is Larkfield example One example is A wrong answer is
Regression A number that can take many values Tickets tomorrow (daily_tickets.csv, column tickets) One day Far or near: 27 for 26 is nearly right
Classification One of a few classes Escalated within 72 hours (escalated_72h: 0 or 1) One ticket Right or wrong
Clustering There is no label Groups of similar customers One customer Not defined: a person judges if the groups are useful

A model costs time to build, to test and to keep working. Three simpler answers are often enough:

  • A rule is a fixed condition that a person writes, for example “flag priority 1 tickets”. It needs no training and is easy to explain.
  • A lookup is a table of facts from the past, for example the escalation rate of each team.
  • A report counts or sums what already happened, for example the escalations of last month.

Choose one of these instead of a model when one of the following is true:

  1. The answer is already in the data. Last month’s escalations need a count, not a prediction.
  2. The answer follows from a known value. “Is the order above $500?” needs order_value > 500, not a model.
  3. A simple rule is good enough. Measure the rule first. A model is worth its cost only if it is clearly better. In Module 2, you measure the rule “flag priority 1”.
  4. No decision changes. If nobody acts on the prediction, do not make it.
  5. There are no examples with the right answer, and no person can judge groups. Then neither supervised nor unsupervised learning can help.

Worked example: each task in the real data

Section titled “Worked example: each task in the real data”

Priya finds each task in the files of the course. Each code block is a cell of the lesson notebook. The notebook first defines read(), which reads a ticket file, the list FEATURES of the 10 feature columns, and TARGET = "escalated_72h". As in Supervised learning, the target is the label column.

Regression. In daily_tickets.csv, one row is one day:

daily = pd.read_csv("data/daily_tickets.csv", parse_dates=["date"])
print(daily.shape)
print(daily.head(3))
print(daily["tickets"].describe().round(2))

The output:

(730, 5)
date weekday is_weekend month tickets
0 2024-07-01 Mon 0 7 33
1 2024-07-02 Tue 0 7 33
2 2024-07-03 Wed 0 7 29
count 730.00
mean 26.35
std 11.12
min 4.00
25% 18.00
50% 26.00
75% 34.00
max 60.00
Name: tickets, dtype: float64

The label tickets goes from 4 to 60, with a mean of 26.35. It is a number, so predicting it is regression. The features of a day are weekday, is_weekend and month. You train this model in Module 4.

Classification. In train.csv, one row is one ticket:

X = train[FEATURES]
y = train[TARGET]
print("X:", X.shape, " y:", y.shape)
print(y.value_counts())

The output:

X: (16939, 10) y: (16939,)
escalated_72h
0 14956
1 1983
Name: count, dtype: int64

X has 16,939 rows and 10 feature columns. y has one value per row, and only two values occur: 0 and 1. This is binary classification.

Clustering. Grace asks: “What kinds of customers do we have?” Priya makes one row per customer from the train tickets. Guests have no customer ID, so she leaves them out:

known = train.dropna(subset=["customer_id"])
customers = known.groupby("customer_id").agg(
tickets=("ticket_id", "size"),
mean_words=("word_count", "mean"),
mean_order=("order_value", "mean"),
segment=("segment", "first"),
).round(1)
print(customers.shape)
customers.head()

The output:

(847, 4)
tickets mean_words mean_order segment
customer_id
C-00001 62 121.2 145.3 business
C-00002 10 114.3 51.1 home
C-00003 2 55.5 27.3 trade
C-00004 14 109.4 53.1 home
C-00005 10 170.6 121.5 home

847 customers, four columns, and no label. A clustering method could find groups such as “customers with many long tickets”. Only Grace can say if such a group helps her team.

No model. A rule, a lookup and a report:

rule_flags = valid["priority"] == 1
print("Rule: flag priority 1 ->", rule_flags.sum(), "of", len(valid), "May tickets flagged")
print()
print("Lookup: escalation rate by team (train)")
print(train.groupby("team")[TARGET].mean().round(3).sort_values(ascending=False))
print()
april = train[train["created_at"] >= "2026-04-01"]
print("Report: April 2026 had", len(april), "tickets and", april[TARGET].sum(), "escalations")

The output:

Rule: flag priority 1 -> 163 of 1179 May tickets flagged
Lookup: escalation rate by team (train)
team
payment 0.207
warranty 0.159
delivery 0.097
returns 0.096
account 0.055
Name: escalated_72h, dtype: float64
Report: April 2026 had 1095 tickets and 107 escalations

The report predicts nothing: April is over. The rule and the lookup do predict, but a person wrote them, and anyone can check them. (valid holds the tickets of May 2026, which are kept apart to check models later; Module 3 explains why.) For Larkfield, Priya decides:

  • Grace’s routing decision is binary classification of one ticket, when the ticket is created. The rule “flag priority 1” is the first thing a model must beat.
  • Omar’s staffing question is regression, and a different project. The course uses it in Modules 3 and 4 to show regression.
  • The customer groups are a question for exploring, not for routing. Unsupervised exploration comes back to them.
  1. Open the notebook from the box Do this lesson in a notebook at the top of this page.
  2. Run the setup cells. The data cell ends with Ready: train 16939 rows (1983 escalated), valid 1179 (183), test 1002 (157).
  3. Run sections 1 to 5. Compare each output with the worked example above.
  4. In section 2, look at the chart of tickets per day. You see fewer tickets at weekends and more in each spring.
  5. In section 6, read the six questions below.
  6. For each question, write "regression", "classification", "clustering" or "no model" in the dictionary answers.
  7. Run the check cell. It prints Check passed when all six answers are right.
  8. If it prints Not yet, ask for each question: what does the answer look like, and is it already known?

The six questions:

  1. How many minutes will the first reply to this new ticket take?
  2. Will this customer write a new ticket within 30 days?
  3. Which tickets are similar, so that the help pages can be grouped by topic? (Nobody has labelled the topics.)
  4. How many tickets did each team get last week?
  5. Is the order value of this ticket above $500?
  6. How many escalations will there be next Monday?
Show the answer
Question Task Why
1. Minutes to the first reply Regression The answer is a number of minutes.
2. A new ticket within 30 days Classification The answer is yes or no, for one customer.
3. Similar tickets for the help pages Clustering There is no label: a person judges the groups.
4. Tickets per team last week No model A report: the answer is already in the data.
5. Order value above $500 No model A rule on a known value gives the exact answer.
6. Escalations next Monday Regression The answer is a count for one day.

Change one thing: the unit. The unit is the thing that one prediction is about: one ticket, one day or one customer. escalated_72h is a classification label, because the unit is one ticket. Make the unit one day instead. In the notebook, section 7, count the escalations on each day of train (group by the date of created_at, and sum escalated_72h). Then compute the mean per day. Before you run it, predict: is the new label for classification or for regression?

Show the answer
escalations_per_day = train.groupby(train["created_at"].dt.date)[TARGET].sum()
mean_escalations = round(escalations_per_day.mean(), 2)
print(mean_escalations)
2.96

The 669 days of train have from 0 to 10 escalations each, with a mean of 2.96. A count per day is a number, so predicting it is regression. The label of each ticket is still yes or no. The unit decides the task, and the decision decides the unit. Grace routes one ticket at a time, so her unit is the ticket.

Common mistake

The wrong unit

Symptom: Tomás proposes a shortcut. “Label each customer as an escalator if they escalated at least once in train. Then send all their tickets to the senior team.” He tests it on the May tickets:

Escalators: 484 of 847 customers
May tickets flagged: 952 of 1179 (80.7%)
Escalations caught: 163 of 183

The rule catches 163 of 183 escalations. It also sends 80.7% of all tickets to the senior team. The senior team can review at most 1 ticket in 5 (20%), so this is four times its capacity.

Cause: Tomás changed the unit from a ticket to a customer. In 22 months, more than half of the customers escalated at least once. So “escalator” says almost nothing about one new ticket. The decision is about one ticket, so the unit must be one ticket.

Fix: before you build anything, write down the unit of the decision: Grace’s team acts on one ticket at a time. Check that the rows of the data, the label and the output all have that unit. Then check the output against what the team can do: what share of tickets would it flag?

Consequence in AI work: a prediction for the wrong unit cannot drive the decision. Here, the senior team cannot review 4 in 5 tickets, so they ignore the flags, and the escalations wait as before. A high count of “caught” cases means nothing until you also count what the rule flags.

Check your understanding

Larkfield wants to know, for each new ticket, how many hours it will stay open. Is this regression, classification or clustering? What is the unit, and when must the prediction be made?

Show the answer

Regression: the answer is a number of hours. The unit is one ticket, and Larkfield needs the prediction when the ticket arrives. The model must know every feature at that moment. So a fact that comes later, such as the time of the first reply, cannot be a feature.

Check your understanding

Omar wants a model that predicts how many tickets were escalated last month, for the monthly report. What do you tell him?

Show the answer

Last month is over, so the answer is already in the data: a report, not a model. Count the escalations with a query or groupby. A model would only add errors to a number that you can count exactly. A model is useful only for answers that do not exist yet when the decision is made.

This practice closes Module 1. It uses everything from the four lessons: machine learning or not, supervised or unsupervised, and the task. You write a task card: a short, fixed set of answers that frames a question before anyone builds a model.

Guided: Priya’s task card for Grace’s question. Read it as a model. Each line answers one question of this module.

Line of the card Grace: “Will this new ticket escalate within 72 hours?”
Who acts on the answer, and how Grace’s team sends flagged tickets straight to the senior team.
The unit (one answer is about one …) Ticket.
What the answer looks like A class: yes or no.
The label in the data escalated_72h, from each ticket’s history 72 hours later.
Learning Supervised: past tickets have the right answer.
Task Binary classification.
A simpler answer to try first The rule “flag priority 1” (163 of 1,179 May tickets).

Independent: three new questions. Write a task card for each question. Then, in section 9 of the notebook, enter the learning ("supervised", "unsupervised" or "none") and the task for each one, and run the check cell.

  • Omar: “How many escalations will there be in each week of next month?”
  • Mei, the data engineer: “Do the tickets of guest customers fall into groups that we do not know about yet?” Nobody has labelled any groups.
  • Grace: “Which team had the most escalations in April?”
Show a model answer
Line of the card Omar: escalations per week Mei: groups of guest tickets Grace: team with most escalations in April
Who acts, and how Omar plans senior staff for each week. Mei and Grace look for problems that guests share. Grace reports to the managers.
The unit Week. Guest ticket. Team, for one past month.
What the answer looks like A number of escalations. Groups that nobody has named. A fact from the past.
The label in the data The weekly count of escalated_72h, from past weeks. None. Not needed: the answer is in the data.
Learning Supervised. Unsupervised. None.
Task Regression. Clustering; a person judges and names the groups. No model: a report (a groupby and a count).
A simpler answer to try first The mean of the last few weeks. A report of guest tickets by team and channel. It is already the simple answer.

In the notebook, the answers are ("supervised", "regression"), ("unsupervised", "clustering") and ("none", "no model").

Check your understanding

What is the difference between supervised and unsupervised learning? Why is supervised learning called supervised?

Show the answer

Supervised learning learns from examples that have the right answer, the label, and learns a rule from the features to the label. It is called supervised because, during learning, a supervisor gives the right answer for every example, as a parent names colours for a child. In data, the label column plays that part. Unsupervised learning has no label. It finds structure in the features alone, such as groups of similar examples, and a person must judge whether that structure is useful.

Check your understanding

Name the task, or say no model: (a) how many minutes a support phone call will last; (b) group returned products by the reason that customers wrote, when no categories exist yet; (c) whether a new product review is positive or negative, with 10,000 past reviews marked by staff; (d) the five products returned most often last month.

Show the answer

(a) Regression: supervised, and the answer is a number of minutes. (b) Clustering: unsupervised, because there are no labels, and a person must name and judge the groups. (c) Classification: supervised, with two classes, and the staff marks are the labels. (d) No model: a report, because the answer is already in last month’s data.

Check your understanding

Explain why Grace's question 'Will this new ticket escalate within 72 hours?' is a supervised learning problem. Where do the labels come from? What could you learn from the same tickets without the label column?

Show the answer

It is supervised because every past ticket has the right answer. escalated_72h is 1 if a senior agent took over the ticket within 72 hours, otherwise 0. The label comes from each ticket’s history, so nobody had to label tickets by hand. A model can learn a rule from the 10 features to this label, and predict it for new tickets. Without the label column, you could only cluster the tickets into groups of similar tickets. That cannot say which new ticket will escalate.

Recap

This lesson

  • The shape of the answer decides the task: a number is regression, a class is classification, groups without a label are clustering.
  • Use a rule, a lookup or a report instead of a model when the answer is already known or follows from a known value. Also use one when a rule is good enough.
  • The unit decides the task. A customer label flags 80.7% of May tickets; Grace’s decision needs one prediction per ticket.

Module 1: Understand machine learning

  • Machine learning learns a rule, the model, from examples (training), and uses it on new cases (prediction). Use it when the pattern is too complex to write, examples exist, the decision repeats and some errors are acceptable.
  • Supervised learning learns from examples with a label (X and y), as a child learns colour names. Unsupervised learning finds groups in the features alone, and a person judges them.
  • Larkfield’s question, “will this new ticket escalate?”, is supervised binary classification of one ticket, with the label escalated_72h.

Reset. Module 1 has no project files yet. To reset a lesson notebook, restart it and run all cells (in Colab: Runtime › Restart session and run all). To start from fresh data, delete the folder ticket-model next to the notebook, then run the setup cells again.

Next, in Module 2, you turn Grace’s need into an exact prediction problem. You name the decision, the unit, the target, the moment of the prediction and the cost of each error.

Next: Translate a need