How machines learn
In traditional programming, a person writes rules: if the email contains "free money", mark it spam. In machine learning, the computer finds the rules itself from examples.
The vocabulary
- Example: one data point, such as one email.
- Features: the measurable inputs describing it (words used, sender, time sent). In deep learning, the raw input (pixels, text) is used and the model discovers its own features.
- Label: the correct answer, if known (spam or not spam).
- Model: a mathematical function that turns features into a prediction. It has adjustable numbers called parameters (or weights).
- Training: adjusting the parameters so predictions match labels.
The learning loop
- Start with a model whose parameters are random or zero.
- Predict on training examples.
- Measure the error with a loss function: a single number saying how wrong the predictions are (for example, the average squared difference between predicted and actual house prices).
- Adjust the parameters to reduce the loss. The standard method, gradient descent, computes which direction to nudge each parameter to make the loss go down, then takes a small step that way.
- Repeat thousands or millions of times.
That's it. Every model from a spam filter to a frontier LLM is trained by some version of this loop. What differs is the model's shape, the data and the scale.
A tiny example
Predict a house's price from its size. The model is a line: price = w × size + b, with two parameters, w and b. Start with random values, compare predictions to real sale prices, and nudge w and b to shrink the error. After training, w might settle at $300 per square foot. The model has "learned" a rule nobody wrote down.
Generalization: the actual goal
A model that memorizes its training data is useless. What we want is generalization: good predictions on new examples it has never seen. Two failure modes:
- Underfitting: the model is too simple to capture the pattern (a straight line for a curved relationship). Bad on training data and new data.
- Overfitting: the model is so flexible it learns noise and quirks of the training set. Great on training data, poor on new data.
Much of practical ML is managing this trade-off: enough flexibility to capture real patterns, not so much that it memorizes noise.
The three kinds of learning
| Type | Learns from | Example |
|---|---|---|
| Supervised | Labeled examples | Predict loan default from past loans and their outcomes |
| Unsupervised | Unlabeled data, finding structure | Group customers into segments |
| Reinforcement | Rewards and penalties from acting in an environment | Teach a robot to walk; train a game-playing agent |
Check your understanding
What does a loss function do?
A model scores 99% on its training data but 60% on new data. It is: