Supervised Learning
Related: 1. Data Exploration and Visualisation | 3. Unsupervised Learning | 7. Evaluating ML Models | 4. Deep Learning and FCNs | Artificial Intelligence
What is Machine Learning?
Machine learning is a set of methods that can automatically detect patterns in data. These patterns are then used to predict future data or perform decision-making under uncertainty.
The Learning Problem
We have a set of training data:
We use this data and an ML method to estimate a function such that .
The relationship is modelled as:
where is an unknown function and is a random error (noise) term.
Terminology:
| Term | Also called |
|---|---|
| Input | Feature, attribute, predictor, independent variable |
| Output | Response, dependent variable, label, ground truth |
Regression vs Classification
| Regression | Classification | |
|---|---|---|
| Output type | Continuous (quantitative) | Categorical (qualitative) |
| Example | Predicting house price | Spam or not spam? |
Linear Regression
The model:
- = constant (y-intercept)
- = coefficient / slope
Least Squares Error — the “best fit” minimises the sum of squared differences between actual and predicted values:
This is minimised using gradient descent (see 6. Loss Functions and Backpropagation).
Strengths: Simple, interpretable, computationally efficient, works well for linearly separable data.
Limitations: Assumes linearity, sensitive to outliers, struggles with multicollinearity, poor with complex non-linear data.
Decision Trees
A decision tree partitions data recursively based on attribute values:
- Determine the best attribute to select as root (using a goodness measure)
- Partition examples into subsets according to values of that attribute
- Construct the tree recursively for each subset
- Exit when all examples belong to one class
Attribute Selection — Information Gain:
Entropy measures impurity:
where is the proportion of class in set .
Entropy after splitting on attribute :
Information Gain:
The attribute with the highest information gain is chosen as the split.
Example (Play Tennis):
| Attribute | Entropy after split | Information Gain |
|---|---|---|
| Outlook | 0.693 | 0.247 (highest) |
| Temperature | 0.911 | 0.029 |
| Humidity | 0.788 | 0.152 |
| Windy | 0.892 | 0.048 |
So Outlook is chosen as the root node.
Strengths: Easy to visualise and interpret, handles non-linear relationships, no need for data normalisation, handles categorical and continuous data.
Limitations: Prone to overfitting (without pruning), sensitive to small data changes.
Random Forest (Ensemble Classification)
Random Forest combines multiple decision trees to reduce overfitting:
- Bootstrapping — train each tree on a random subset of data with replacement
- Feature subsampling — use a random subset of features at each split
- Tree building — grow individual trees independently
- Aggregation — combine results using majority vote (classification) or averaging (regression)
Strengths: Reduces overfitting, handles high-dimensional data.
Limitations: Less interpretable, computationally intensive, requires hyperparameter tuning.
K-Nearest Neighbours (KNN)
A lazy learning approach — no model is built; the entire dataset is retained. KNN uses the same distance metrics as clustering.
Algorithm:
- User inputs (number of neighbours)
- For each unlabelled instance, calculate the distance to all training instances
- Find the nearest neighbours
- Classification: majority vote among neighbours
- Regression: average of the target values:
Distance metrics:
- Euclidean:
- Manhattan:
Strengths: Simple, no assumptions about distribution, effective for non-linear problems.
Limitations: Computationally expensive at prediction time, performance depends on choice of and distance metric, sensitive to irrelevant/noisy features.