- Machine learning learns patterns from examples instead of hand-written rules.
- AI is the broad goal, ML is a way to build it, and deep learning is ML with deep neural networks.
- Training changes the parameters; inference uses them on new inputs without labels.
No earlier lesson is required. Next, Linear Regression & Loss makes the loop concrete with a line and a number you can check by hand.
1. A filter written by hand
Suppose you want a spam filter. One approach is to write rules: “block a message if it contains free, prize, or click here.” The rules work until a real message says “free meeting” or a spammer writes “fr3e.” Every exception needs another rule, and the list grows without learning anything from the messages themselves.
Machine learning takes a different route. You show the system many examples of inputs and the answer you want. Each input is a feature vector x. The desired answer is the label y. The system learns a model that maps an input to a prediction.
ŷ is the prediction. The model has parameters θ: the numbers it is allowed to adjust. For the spam filter, an input could be the counts of a few words, and the prediction could be a score between 0 and 1.
A loss function scores the miss. With a prediction of 0.8 and a label of 1, squared error gives (0.8 − 1)² = 0.04. A prediction of 0.1 on the same label gives 0.81: much worse.
The loss turns “how wrong” into one number. Training searches for parameters that make that number small on the examples.
2. The learning loop
The same loop sits under a spam filter, a house-price predictor, and a language model. Scrub the story and watch where the label goes.
A training set is a collection of input–label pairs:
The loss over the whole set is the average of the per-example losses:
Training repeats the loop: predict, score, adjust. The adjustment step is where optimization enters. A gradient tells the model which way to move; the learning rate says how far. You will build that step in the next two lessons.
3. AI, ML, and deep learning
The three words are often used as synonyms. They are nested, not parallel:
The broad goal: systems that make useful decisions or predictions.
A way to build AI: learn patterns from data instead of writing every rule.
ML with deep neural networks. It is one family of ML, not a separate universe.
A decision tree is ML but not deep learning. A large language model is both. The nesting matters because a claim about “AI” can be much broader than a claim about one model family.
4. Four learning signals
A learning signal tells the model what “better” means. The signal is not always a human-written label.
| Signal | Where the target comes from | Example |
|---|---|---|
| Supervised | A person supplies the label | “spam” / “not spam” |
| Self-supervised | The data hides part of itself | predict the next token |
| Unsupervised | No target; find structure | group similar customers |
| Reinforcement | A reward after actions | a game score at the end |
Next-token prediction is self-supervised, not unsupervised: the next word is hidden, but it is already in the text, so the data supplies the answer. Clustering receipts with no labels is unsupervised. A game score is a reinforcement signal.
A model reads a sentence with one word covered and is asked to predict the covered word. Is that supervised, self-supervised, unsupervised, or reinforcement learning?
5. Labels are not inputs
A label belongs on the answer side. If it leaks into the input, the model can copy the answer and look perfect while learning nothing useful. This is label leakage.
Imagine a hospital dataset where one column says whether the patient was readmitted. If you put that column in the input, the model can read the future. On a new patient, the column is blank, and the model collapses. A file named cat.jpg in an image classifier is the same trap.
A model gets 100% training accuracy because the target column is also included as an input. What is the first thing to check?
6. Training and inference
Training changes the parameters. Inference uses fixed parameters to answer a new question. The same model can do both, but the label is available only during training.
This is also why a test set has to stay out of training. If a test label changes the weights, the example is no longer a test. A validation set is the same idea: it helps you choose between models without becoming training data.
The loop also needs a starting point. Before any examples, the parameters are just numbers. Training is the process that moves them; inference is what you ship.
7. The majority classifier
A model does not have to use its input. Take five emails: three normal and two spam. The laziest model always predicts the majority class, normal.
Worked example: the laziest possible model
| label | always-normal prediction | correct? | |
|---|---|---|---|
| meeting notes | 0 | 0 | yes |
| free money | 1 | 0 | no |
| project update | 0 | 0 | yes |
| prize winner | 1 | 0 | no |
| lunch? | 0 | 0 | yes |
The model ignores every email and still gets 60% (3 of 5). On a dataset that is 99% normal, the same lazy model gets 99%. Accuracy alone can hide a model that never uses the input.
This is why a baseline matters. A real model has to beat the lazy one on data it has not seen. It also needs a metric that reflects the cost of different mistakes: missing spam and blocking a real email are not equally bad.
8. Where machine learning struggles
ML is not a magic box that turns any data into truth. It struggles when the examples are unrepresentative, when labels are noisy or leaky, when the world changes after training, and when a decision requires a guarantee that the data cannot provide.
It also struggles with small data. A pattern learned from ten examples may be a coincidence. More data helps only if it covers the situations the model will meet.
The next question is the one that makes learning concrete: how do we turn “wrong” into a number we can minimize? The next lesson fits a line to data and watches that number become a landscape.
Next: Linear Regression & Loss
9. Practice
A model predicts 7 and the target is 5. What is the squared error?
A model is trained on 1,000 labelled x-rays and then used on a new x-ray with no label. Which phase is the new x-ray?
A model has 99% training accuracy and 60% validation accuracy. What should you suspect before celebrating?
10. Resources
Start with the Crash Course for a broad tour, then read the MIT notes for a precise treatment of hypotheses, loss, and validation. Both links were opened and checked for this lesson.