Part 1: Start hereChapter 1 of 159
What is machine learning?
Beginner4 min1 code sample3 review cards
Ordinary programming works like a recipe: a person writes the rules, the computer follows them. That breaks down the moment the rules are too many, too fuzzy or simply unknown. Nobody can write down the rules for recognising a cat, a spam email or a good chess move. Machine learning flips the arrangement: you give the computer examples with the right answers, and it works out the rules itself.
What you will learn
- Explain the difference between writing rules and learning them from examples
- Fit a model to data and use it to predict a value it has never seen
- Name supervised, unsupervised and reinforcement learning and give an example of each
Rules in, or rules out#
| Classical programming | Machine learning | |
|---|---|---|
| You provide | Rules and data | Data and the right answers |
| The computer produces | Answers | The rules (a model) |
| Good when | The rules are known and exact | The rules are unknown, fuzzy or too many |
| Example | Compute tax from a formula | Detect spam from thousands of labelled emails |
The "rules" a model learns are not if-statements. They are numbers, called parameters or weights, inside a fixed mathematical shape. Learning means finding good values for those numbers.
A model that learns a rule#
Here is the smallest honest example. We pretend not to know how to convert Celsius to Fahrenheit and let the computer discover it from seven measured pairs. The model is a straight line, f = w × c + b, and "learning" means choosing the slope w and the intercept b that fit the examples best.
import numpy as np
celsius = np.array([-40, -10, 0, 15, 22, 37, 100], dtype=float)
fahrenheit = np.array([-40, 14, 32, 59, 71.6, 98.6, 212])
# The model is f = w * c + b. Least squares finds the w and b that make the predictions closest to the answers.
design = np.column_stack([celsius, np.ones_like(celsius)])
w, b = np.linalg.lstsq(design, fahrenheit, rcond=None)[0]
print(f"learned rule: f = {w:.3f} * c + {b:.3f}")
print(f"prediction for 30 C: {w * 30 + b:.1f} F (the true value is 86.0 F)")
# Now with messy data: add measurement noise and see that the model still finds almost the same rule.
rng = np.random.default_rng(0)
noisy = fahrenheit + rng.normal(0, 3, size=fahrenheit.shape)
w2, b2 = np.linalg.lstsq(design, noisy, rcond=None)[0]
print(f"from noisy data: f = {w2:.3f} * c + {b2:.3f}")Output from a real run
learned rule: f = 1.800 * c + 32.000 prediction for 30 C: 86.0 F (the true value is 86.0 F) from noisy data: f = 1.825 * c + 32.357
Nobody told the program that the answer is 1.8 and 32. It found them from examples, and with noisy examples it found numbers close to them. That is the whole idea; every model in this course, from a spam filter to a language model with hundreds of billions of parameters, is a bigger version of this move: choose a shape, then find the parameter values that fit the data.
Quick check
In the Fahrenheit example, what exactly did the computer learn?
Three ways to learn#
- Supervised learning: examples come with answers (labels). Predict a number (regression: house price) or a category (classification: spam or not). Most of the models in this course are of this kind.
- Unsupervised learning: no answers. Find structure on your own: group similar customers (clustering), compress data, find the odd one out.
- Reinforcement learning: no answers either, but a reward. An agent tries actions in an environment and learns which ones earn the most reward over time (games, robots, tuning language models).
A fourth mode now dominates headlines: self-supervised learning. The data supplies its own labels, for example "predict the next word of this sentence", so the world's text becomes a training set with no human labelling. Large language models are trained this way (chapter 94).
What it is good at, and what it is not#
Machine learning shines when there is plenty of example data, the pattern is stable, and a good-enough answer is useful: recognising images and speech, ranking, recommending, forecasting, translating, generating text. It struggles when examples are scarce, when the world changes under the model, when mistakes are very costly, and whenever you need to know why with certainty. A model finds patterns in the data it saw; it does not understand the world the way a person does, and it will confidently extrapolate patterns that do not hold.
Check yourself
Answer in your head first, then open the answer and say how it went. That is what schedules your review.
What is the difference between a classical program and a machine-learning model?
Name one example each of supervised, unsupervised and reinforcement learning.
Finished this chapter?
Your progress is saved in this browser.
Up next: 2. The map: AI, machine learning, deep learning and generative AI · 4 min
3 questions from this chapter are in your review queue.Practise your reviews
About this chapter
This unlocks2. The map: AI, machine learning, deep learning and generative AI3. How models learn: the training loop7. Python for AI: the small parts you need
On the learning pathsAI from zeroMachine learning engineer
Checked against python 3.14, numpy 2.5, scipy 1.18, scikit-learn 1.9, pandas 3.1, torch 2.14, gymnasium 1.4 on 2026-10-24. AI moves fast, and library versions, model names and prices change often. Where current documentation disagrees with this page, trust the documentation, and tell us on the corrections page.