For most of this guide, a computer did exactly what it was told: a programmer wrote the rules, and the machine followed them. Machine learning inverts that relationship. Instead of writing the rules, you show the machine examples and let it infer the rules itself. You don't program the answer — you program a process that finds the answer in data.
This matters because some problems are easy to demonstrate but nearly impossible to specify. Nobody can write down the exact rules that distinguish a cat from a dog in a photograph, but anyone can label ten thousand photos. Machine learning is the trade of turning examples into a program.
Learning From Data, Not Rules
A traditional program is rules + input → output. Machine learning flips two of those terms: it takes input + output → rules. You feed in examples (inputs paired with their correct outputs) and the learning algorithm produces a model — a function with adjustable internal numbers, called parameters (or weights), that approximates the relationship.
Analogy: Teaching by rules is writing someone a recipe. Machine learning is letting them taste a hundred finished dishes until they can cook the dish themselves — they never see your recipe, they reconstruct one that produces the same result.
The Three Kinds of Learning
Almost every ML system falls into one of three families, distinguished by what signal the model learns from:
- Supervised learning is the workhorse: every training example comes with the correct answer (a label). The model's job is to predict the label for inputs it has never seen. Spam filters, medical-image classifiers, and price predictors are all supervised.
- Unsupervised learning has no labels at all — only raw data. The model finds structure on its own: clusters of similar customers, anomalies in a stream of transactions, or compressed representations. The embeddings that power modern search (Chapter 66) are learned this way.
- Reinforcement learning has no fixed answers, only rewards. An agent takes actions, receives feedback, and learns a strategy that maximizes reward over time. It powers game-playing systems and, as we'll see in Chapter 64, the final polishing step of modern chatbots.
Features, Model, Loss
Three ideas recur in every supervised system:
| Term | What it is |
|---|---|
| Features | The input variables the model sees — square footage, pixel values, the words in an email |
| Model | A function with tunable parameters that maps features to a prediction |
| Loss | A single number measuring how wrong the predictions are on the training data |
Training is then a search: adjust the parameters to make the loss as small as possible. The loss is the compass — it points the entire process toward "less wrong."
The Training Loop
Learning happens by repetition. The model makes predictions, measures its error, and nudges its parameters to do slightly better — over and over, sometimes millions of times:
This loop is the beating heart of nearly all machine learning, and the next chapter shows exactly how the "nudge each parameter" step works for neural networks.
Generalization — The Whole Point
Here is the subtle part: doing well on the training data is not the goal. A model that simply memorizes its examples is useless — like a student who memorizes the practice exam but can't answer a new question. The real goal is generalization: performing well on data the model has never seen.
To measure it, you split your data: train on one portion, then evaluate on a held-out test set the model never trained on. The gap between training and test performance reveals the central failure mode of ML:
Analogy: Underfitting is a student who didn't study enough to grasp the material. Overfitting is a student who memorized the textbook word-for-word but can't apply any of it. A good fit is the student who understood the concepts — and can answer questions they've never seen.
Everything that follows — neural networks, transformers, the models behind ChatGPT and Claude — is an elaboration of this one idea: adjust millions of parameters to minimize a loss, in a way that generalizes beyond the data you trained on.