Choose the learning task
- Lesson 4
- 60 min
- Module 1: Understand machine learning
Lesson 4 of 27 · Machine Learning: From Problem to Reliable ModelChoose the learning task
1. Understand machine learning
2. Frame the prediction problem
3. Evaluate supervised models
4. Build the first models
5. Try other model families
6. Tune and finish the model
7. Understand and choose the model
8. Prepare the model for handoff
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 notebook
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 ready
What you need to know
- When machine learning helps and when a rule is better, from What machine learning is.
- Features and labels, classification and regression, from Supervised learning.
- Clustering, and why a person must judge the clusters, from Unsupervised learning.
groupbyandaggin pandas, from Transform with Python in SQL and Data Preparation for AI.
What you need on your computer (only for the local route; the notebook needs none of it)
- Nothing yet. You make the project folder
~/projects/ticket-modelin the next module, in Define a baseline: Set up your project.
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.
One weather service, four kinds of answer
Section titled “One weather service, four kinds of answer”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.
Four questions, four kinds of answer
Section titled “Four questions, four kinds of answer”Larkfield’s team asks the same four kinds of question about its help desk:
- 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.
- 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. - 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.
- 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 |
The task follows from the decision
Section titled “The task follows from the decision”You can find the task for any question with three questions, in this order. The diagram shows them.
- 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.
- 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.
- If there is a label, what does the answer look like? A number means regression. A class means classification.
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 |
When no model is the right answer
Section titled “When no model is the right answer”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:
- The answer is already in the data. Last month’s escalations need a count, not a prediction.
- The answer follows from a known value. “Is the order above $500?” needs
order_value > 500, not a model. - 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”.
- No decision changes. If nobody acts on the prediction, do not make it.
- 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 tickets0 2024-07-01 Mon 0 7 331 2024-07-02 Tue 0 7 332 2024-07-03 Wed 0 7 29count 730.00mean 26.35std 11.12min 4.0025% 18.0050% 26.0075% 34.00max 60.00Name: tickets, dtype: float64The 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_72h0 149561 1983Name: count, dtype: int64X 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 segmentcustomer_idC-00001 62 121.2 145.3 businessC-00002 10 114.3 51.1 homeC-00003 2 55.5 27.3 tradeC-00004 14 109.4 53.1 homeC-00005 10 170.6 121.5 home847 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"] == 1print("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)teampayment 0.207warranty 0.159delivery 0.097returns 0.096account 0.055Name: escalated_72h, dtype: float64
Report: April 2026 had 1095 tickets and 107 escalationsThe 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.
Guided practice: name the task
Section titled “Guided practice: name the task”- Open the notebook from the box Do this lesson in a notebook at the top of this page.
- Run the setup cells. The data cell ends with
Ready: train 16939 rows (1983 escalated), valid 1179 (183), test 1002 (157). - Run sections 1 to 5. Compare each output with the worked example above.
- In section 2, look at the chart of tickets per day. You see fewer tickets at weekends and more in each spring.
- In section 6, read the six questions below.
- For each question, write
"regression","classification","clustering"or"no model"in the dictionaryanswers. - Run the check cell. It prints
Check passedwhen all six answers are right. - If it prints
Not yet, ask for each question: what does the answer look like, and is it already known?
The six questions:
- How many minutes will the first reply to this new ticket take?
- Will this customer write a new ticket within 30 days?
- Which tickets are similar, so that the help pages can be grouped by topic? (Nobody has labelled the topics.)
- How many tickets did each team get last week?
- Is the order value of this ticket above $500?
- 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. |
Your turn: change the unit
Section titled “Your turn: change the unit”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.96The 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 customersMay tickets flagged: 952 of 1179 (80.7%)Escalations caught: 163 of 183The 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.
Knowledge check
Section titled “Knowledge check”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.
Does your answer have the main points of ours?
Sign in and enroll in the course to save your answers. Every check counts toward the certificate.
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.
Does your answer have the main points of ours?
Sign in and enroll in the course to save your answers. Every check counts toward the certificate.
Module practice
Section titled “Module practice”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").
Module check
Section titled “Module check”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.
Does your answer have the main points of ours?
Sign in and enroll in the course to save your answers. Every check counts toward the certificate.
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.
Does your answer have the main points of ours?
Sign in and enroll in the course to save your answers. Every check counts toward the certificate.
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.
Does your answer have the main points of ours?
Sign in and enroll in the course to save your answers. Every check counts toward the certificate.
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 (
Xandy), 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