What Machine Learning Really Means

Learning the rule from examples instead of writing it

Advanced 13 min

In this lesson

Unit 12 let you describe what happened. This unit is about predicting what happens next, and about being honest when the prediction is not good enough to use.

Machine learning has an unhelpful reputation. Strip the marketing away and it is a plain idea: instead of writing the rule yourself, you show the computer enough examples that it works the rule out.

Explain it like I’m 5

Machine learning is teaching the computer from examples instead of writing every rule by hand — like learning what a cat looks like by seeing hundreds of cats rather than reading a description.

Features and labels

Two words carry most of the vocabulary, and they map onto the table you already know from Unit 12.

A feature is an input column, a fact you know. A label (also called the target) is the output column, the thing you want to predict. Every row is one example pairing its features with its answer.

Naming which columns are which is the first decision in any project, and getting it backwards is a surprisingly common way to waste an afternoon.

Example
houses = [
    {"size_m2": 50,  "bedrooms": 1, "price_k": 150},
    {"size_m2": 75,  "bedrooms": 2, "price_k": 205},
    {"size_m2": 110, "bedrooms": 3, "price_k": 295},
]

FEATURES = ["size_m2", "bedrooms"]
LABEL = "price_k"

for house in houses:
    inputs = [house[name] for name in FEATURES]
    print(f"features {inputs} -> label {house[LABEL]}")

print("rows:", len(houses), "| features per row:", len(FEATURES))
Output
features [50, 1] -> label 150
features [75, 2] -> label 205
features [110, 3] -> label 295
rows: 3 | features per row: 2
Three examples. Two features in, one label out.

A rule you write, versus a rule the data gives you

Here is the whole distinction in one example. You could decide that houses cost about $2,700 per square meter and write that number into your code. Or you could let the examples tell you the number.

The second is machine learning, and it is not any more magical than the first: it is arithmetic over your data. What it buys you is that when the data changes, the rule updates itself.

Example
# The hand-written rule: a human decides the number.
def rule_based(size_m2):
    return size_m2 * 2.7

# Learning from examples: work the number out from the data itself.
sizes = [50, 75, 110]
prices = [150, 205, 295]
learned_rate = sum(prices) / sum(sizes)

print("human guess per m2:", 2.7)
print("learned per m2:    ", round(learned_rate, 3))
print("rule predicts 90m2: ", round(rule_based(90), 1))
print("learned predicts:   ", round(90 * learned_rate, 1))
Output
human guess per m2: 2.7
learned per m2:     2.766
rule predicts 90m2:  243.0
learned predicts:    248.9
Two rules, six pounds per square meter apart.

Supervised, unsupervised, and where you are

Almost everything in this unit is supervised learning: your examples come with the right answers attached, and the model learns to reproduce them. House prices you already sold at, emails already marked as spam.

Unsupervised learning has no answer column. You hand over the data and ask what structure is in it: which customers behave alike, for instance. It is genuinely useful and a much harder thing to evaluate, because there is nothing to check against.

Supervised problems split in two, and they are the next two lessons. Predicting a number is regression. Predicting a category is classification.

Name the label for three prediction problems. Each description says what you want to predict. Fill in the column name that would hold that answer, using "price", "is_spam" and "temp_tomorrow". Getting this right is the first step of every project.

DATASETS = {
    "predict house price from size and bedrooms": "?",
    "predict if an email is spam from word counts": "?",
    "predict tomorrow's temperature from today's": "?",
}

for description, label in DATASETS.items():
    print(f"{label:14s} <- {description}")

print("datasets:", len(DATASETS))

Why evaluation is the whole game

A model always produces an answer. It has no way to say “I do not know”, and it will confidently predict a house price from nonsense inputs.

So a prediction on its own is worthless. A prediction plus a measure of how wrong it usually is is useful. That is why every lesson in this unit pairs a prediction with a score, and why a model with no evaluation should never be trusted with a decision.

The other half of that honesty is the data. A model trained on the last decade's hiring decisions learns the last decade's biases, faithfully and invisibly. It is not neutral for being arithmetic — it reproduces whatever the examples contained, including the parts nobody intended.

Common mistake: Thinking machine learning is magic

Why it happens:

The results can be impressive and the vocabulary is deliberately grand.

How to fix it:

It is arithmetic that finds a rule in examples. Knowing that makes it much easier to reason about when it will fail.

Common mistake: Using a model where a rule would do

Why it happens:

Machine learning sounds like the more capable answer.

How to fix it:

If you can state the rule, write it. It will be faster, testable, and explainable to whoever asks.

Common mistake: Ignoring bad or biased training data

Why it happens:

Training succeeds regardless of whether the data deserved to be trusted.

How to fix it:

Check what the examples represent before training. A model reproduces the patterns in its data, including the ones you would not endorse.

Common mistake: Mixing up features and the label

Why it happens:

They are all just columns in the same table.

How to fix it:

Features are what you know; the label is what you want to find out. Write both down before any code.

What is a feature?

What is a label?

Why must you test a model?

Mini exercise (easy)

Sort six prediction problems into the two kinds of supervised learning. Mark each "regression" if the answer is a number, or "classification" if the answer is a category. This one distinction decides which tools you reach for in the next two lessons.

Have a go. Finish the code and press Run to see the result immediately, right on this page.

# Mark each problem "regression" if the answer is a NUMBER,
# or "classification" if the answer is one of a fixed set of CATEGORIES.
PROBLEMS = {
    "predict a house price in pounds": "?",
    "predict whether an email is spam": "?",
    "predict tomorrow's temperature": "?",
    "predict which of three flower species": "?",
    "predict how many minutes a delivery takes": "?",
    "predict whether a student passes or fails": "?",
}

for problem, kind in PROBLEMS.items():
    print(f"{kind:14s} {problem}")

counts = {k: list(PROBLEMS.values()).count(k) for k in ("regression", "classification")}
print("regression:", counts["regression"], "| classification:", counts["classification"])

What to learn next

You separated the vocabulary from the mystique: features are the inputs, the label is what you want to predict, and machine learning is working the rule out from examples rather than writing it yourself. You also saw that most problems do not need it, and that a model reproduces whatever its data contained.

Now build one. Regression: Predicting Numbers draws a line through your examples and — just as importantly — measures how far off it usually is.