Supervised learning
The examples include target answers. Typical tasks include predicting prices, classifying images and detecting fraud.
Machine learning models · Lesson 1
A model is not a magic brain. It is a mathematical structure fitted to examples so it can produce useful outputs for new cases.
After this lesson, you should be able to name the main parts of a machine-learning system, distinguish the model from the training algorithm, classify the four broad learning settings, and explain why unseen data is the real test.
A machine-learning system uses examples to find a pattern that is useful beyond the examples it saw during training.
A useful first approximation is:
prediction = model(input; learned parameters)
In mathematical shorthand, this is often written as ŷ = fθ(x). The input is x, the model is f, the learned parameter values are θ, and the prediction is ŷ.
For a spam filter, the input might include the sender, words, links and message metadata. The output might be a probability such as “92% spam”. A decision rule can then turn that probability into an action.
Probabilistic models may output a whole distribution rather than one answer. The central idea is unchanged: input goes in, a fitted mathematical object produces an output.
| Term | Meaning | Spam example |
|---|---|---|
| Dataset | Examples used for learning. | A collection of emails. |
| Feature | An input signal available to the model. | Number of links or sender domain. |
| Target | The answer we want to predict. | Spam or not spam. |
| Model | The mathematical form used to produce predictions. | A classifier. |
| Parameter | A value learned from the training data. | How strongly a feature affects the result. |
| Hyperparameter | A setting chosen by the developer. | Tree depth or learning rate. |
| Loss | A score describing how wrong a prediction is. | A penalty for a wrong classification. |
| Algorithm | The procedure used to fit the model. | Gradient descent or tree splitting. |
The examples include target answers. Typical tasks include predicting prices, classifying images and detecting fraud.
No target answer is supplied. The model looks for groups, structure, compressed representations or unusual cases.
The system creates a prediction task from unlabelled data, such as hiding a word and learning to predict it.
An agent interacts with an environment and learns which actions tend to produce better future rewards.
Self-supervised learning still uses a target. The difference is that the target is generated from the data rather than manually supplied by a person.
Every model makes a bet about what useful patterns look like. This built-in preference is often called an inductive bias.
| Family | Underlying bet | Useful first situation |
|---|---|---|
| Linear models | Effects combine in a relatively simple way. | Small or medium tabular problems and interpretable baselines. |
| Trees and ensembles | Useful decisions can be represented as feature splits. | Tabular data with nonlinear interactions. |
| Nearest neighbours | Similar cases should have similar outputs. | Problems where similarity has a meaningful definition. |
| Probabilistic models | Uncertainty and hidden relationships should be represented explicitly. | Limited data, sequences and uncertain decisions. |
| Neural networks | Layered transformations can learn useful representations. | Images, audio, text and high-dimensional data. |
A more complex model is not automatically a better model. A boosted-tree model may beat a neural network on ordinary business data while being cheaper and easier to explain.
Training is the fitting stage. The model makes predictions, a loss function measures error, and an optimisation procedure adjusts the parameters. This repeats across many examples.
Inference is using the fitted model on new input. In Python, a library might expose this as:
model.fit(X_train, y_train)
prediction = model.predict(X_new)
The first line represents training. The second represents inference. A model can perform well during training and still fail during inference if it has memorised the training examples rather than learned a general pattern.
Generalisation means performing well on new data from the same kind of environment as the training data. This is the real purpose of machine learning.
Overfitting happens when a model learns the training data too closely, including noise and accidental details. The usual pattern is strong training performance and weak test performance.
Underfitting happens when a model is too limited to capture the useful pattern. Training performance and test performance are both poor.
Data leakage happens when information enters training that would not be available at the time of the real prediction. For example, predicting cancellation using a field recorded only after a customer has cancelled produces an impressive but unusable model.
Start with the problem, not the fashionable architecture.
A sensible progression is often:
simple rule → linear model → tree-based model → neural network → specialised model
Move towards the right only when the simpler approach is not good enough for the actual requirement.
Choose one prediction problem from your work or life. Write down the input features, target, prediction, loss and one reason a simple baseline might be better than a large neural network.
Answer these without reopening the lesson if you can. The point is recall, not recognition.
1. Which statement best distinguishes a model from an algorithm?
2. Predicting a labelled house price is primarily which setting?
3. A model scores well on training data but poorly on test data. What is the likely diagnosis?
4. Why might a tree-based model be a sensible first baseline for tabular customer data?
Next lesson: data, targets, loss functions and why evaluation is harder than it first appears.