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:

TermAlso called
Input Feature, attribute, predictor, independent variable
Output Response, dependent variable, label, ground truth

Regression vs Classification

RegressionClassification
Output typeContinuous (quantitative)Categorical (qualitative)
ExamplePredicting house priceSpam 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:

  1. Determine the best attribute to select as root (using a goodness measure)
  2. Partition examples into subsets according to values of that attribute
  3. Construct the tree recursively for each subset
  4. 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):

AttributeEntropy after splitInformation Gain
Outlook0.6930.247 (highest)
Temperature0.9110.029
Humidity0.7880.152
Windy0.8920.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:

  1. Bootstrapping — train each tree on a random subset of data with replacement
  2. Feature subsampling — use a random subset of features at each split
  3. Tree building — grow individual trees independently
  4. 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:

  1. User inputs (number of neighbours)
  2. For each unlabelled instance, calculate the distance to all training instances
  3. Find the nearest neighbours
  4. Classification: majority vote among neighbours
  5. 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.