Should you use machine learning?
Last updated
Machine learning is one tool among many, and often not the right one. Before any model, ask four questions: could a rule do it, are there examples with answers, do they look like the real world the model will meet, and who pays for its mistakes? If machine learning survives those, frame the problem so that a model can be judged: what goes in, what comes out, how it's scored, and what it must beat.
By the end of this lesson you can
- Decide whether a problem needs machine learning, a rule, or more data first
- Frame a problem as a task, features, a label, a metric and a baseline
- Weigh the cost of each kind of mistake, and who bears it
Wrong way: learning what a rule already decides
Is a year a leap year? Here's a decision tree (lesson 4.4 explains them) that learned it from 99 examples, the years 1901 to 1999, with the right answer for each:
A perfect score on its training years, using 49 leaves. Now ask it about years it hasn't seen, and ask the rule too:
The tree says none of 2000, 2024, 2025 and 2100 is a leap year; it gets two of the four wrong. It never learned "divisible by 4"; it learned 49 little ranges of years between 1901 and 1999, and outside them it just repeats the answer at the edge.
The rule, year % 4 == 0 and (year % 100 != 0 or year % 400 == 0), is right for every year there will ever be, costs nothing to run, and anyone can check it. When the answer follows from a rule you can write down, write it down. Tax brackets, a shop's opening hours, whether a password is long enough, converting kilometres to miles: none of these needs learning.
Machine learning earns its place when the rule exists but nobody can write it: what makes a photo a cat, a message spam, a tumour malignant.
What the data must have
If a rule won't do, a supervised model needs three things from its data:
- Examples. Enough of them, of every kind the model must handle. Lesson 4.13's learning curves show how to tell whether more would help.
- The right answers. Labels, and correct ones. Someone has to make them, which costs time and money, and labellers disagree (is this X-ray clear or not?). A model can't be more right than its labels.
- The same world as use. The examples must come from the same place the model will work: the same kind of people, the same sensors, the same season. A model trained on Manila's traffic will meet Cebu's as a stranger. Lesson 4.14 shows a house-price model trained on southern California whose error grows by almost a quarter in the north.
If one is missing, getting it is the first job, before any model. A datasheet for the data (Gebru et al.) asks the questions: who collected it, when, how, of whom, and who's left out?
Framing the problem
"Use AI to improve our clinic" isn't a problem a model can solve. A framed problem names five things:
| Example: a clinic's no-shows | |
|---|---|
| The decision | Which patients to call the day before |
| The task | Classification: will this booking be a no-show? (lesson 2.2) |
| Features, | Days since booking, past no-shows, distance, time of day, as known when the call is made |
| The label, | Did they come? From last year's records |
| The metric | Recall among the 50 calls a day the clinic can make (lesson 2.8) |
Two traps hide in the features row. Every feature must be known at the moment of prediction: "the patient arrived late" isn't known the day before. And the label must be what you really care about. "Clicked the ad" isn't "liked the product", and a model will chase whatever you measure.
A baseline to beat
Before any model, find the score of the simplest thing that could work: always the commonest class (lesson 2.8), the mean (lesson 2.11), or a rule written by someone who knows the field. For the penguins, two lines of rule against a tuned -NN:
Two ifs get 94.7%. -NN, cross-validated, gets 95.9%. The model wins, but by about four penguins in 342. Is that worth a model to train, store, test and keep up to date, instead of a rule anyone can read? Sometimes yes, often no. Without the baseline, "95.9%" sounds impressive and you'd never ask.
Who is affected, and what happens when it's wrong
Every model makes mistakes. Before building one, ask who pays for them:
- Which mistakes, and how bad? A spam filter that lets spam through annoys; one that hides a job offer costs someone a job. A screening test that misses a disease is worse than one that sends a healthy person for a second test. Lesson 2.8's precision and recall are how you trade one against the other.
- Who's affected, and are they in the data? A model trained mostly on one group can be confidently wrong about another. Check the errors for each group, not just overall.
- Can a mistake be caught and undone? A recommendation can be ignored. A refused loan, a flagged account, a missed diagnosis may never be looked at again. The harder a mistake is to undo, the more a person should make the final call, with the model at most helping.
- What happens later? The world changes, and the model doesn't, unless someone watches it (lesson 4.14).
The Philippines' Data Privacy Act and similar laws elsewhere also apply to the data you train on: personal data needs a lawful purpose, and people have a right to know how decisions about them are made.
The whole decision
The four questions, in order, as a UML activity diagram:
Press Walk through it to follow the work round the chart, one stop at a time.
- Name the decision the model would help with.
- Can a rule or a lookup decide it? If yes, write the rule; no ML is needed.
- Are there examples, with the right answers? If no, collect and label data first.
- Is it like the data it will meet in use? If no, get data from the real setting.
- Can the people affected live with its mistakes? If no, keep a person deciding, or don’t build it.
- Otherwise, frame it (X, y, a metric, a baseline) and try machine learning.
It ends at "try ML", not "use ML": the model still has to beat the baseline, on data it hasn't seen, by enough to be worth keeping. Lesson 4.14 follows a project from here to the end.
Check what you learned
Sources
Every example on this page was run with Python 3.14, and its output and error messages are copied from it. These pages cover the same ground in more depth.
- Domingos, A few useful things to know about machine learning, Communications of the ACM 55(10), 2012: what learning can and can't do, and why data and features matter most
- Amershi et al., Software engineering for machine learning: a case study, ICSE-SEIP 2019: the stages of an ML project at Microsoft, from requirements to monitoring
- Gebru et al., Datasheets for datasets, Communications of the ACM 64(12), 2021: questions to ask of any data set: who collected it, how, and for what