Unsupervised Learning

Related: 2. Supervised Learning | 1. Data Exploration and Visualisation | 12. Autoencoders | Artificial Intelligence


Clustering

Clustering is a type of unsupervised learning that groups similar objects together. The training data contains no output labels.

Goals: data reduction, outlier detection, missing value imputation, pattern discovery.

Key principle: maximise within-cluster similarity, minimise between-cluster similarity.

Similarity measures (same as KNN):

  • Euclidean distance
  • Manhattan distance

Cluster Quality Measures

  • Cluster centre — for numeric data, the centre of mass (mean); for nominal data, the mode
  • Within-cluster variation (wc) — how compact/tight clusters are
  • Between-cluster variation (bc) — distances between different clusters

K-Means Algorithm

  1. Define the number of clusters
  2. Choose data objects randomly as initial centroids
  3. Assign each data object to its nearest centroid
  4. Recalculate the centroid of each cluster as the mean of its members
  5. Repeat steps 3–4 until cluster membership no longer changes

Finding optimal — Elbow Method:

Plot within-cluster sum of squares (WCSS) against . The “elbow” point where adding more clusters no longer significantly reduces WCSS is the optimal .

Strengths: Simple, efficient.

Weaknesses: Must specify in advance, sensitive to initialisation, sensitive to noise, struggles with non-globular cluster shapes.

Agglomerative (Hierarchical) Clustering

A bottom-up approach — no need to specify beforehand.

Algorithm:

  1. Treat all data objects as individual clusters; build an dissimilarity matrix
  2. While number of clusters > 1:
    • Find the pair with minimum distance
    • Merge them into a bigger cluster
    • Update the distance matrix
  3. Produces a dendrogram

Measuring distance between clusters:

MethodDescription
Single linkDistance between the two closest points
Complete linkDistance between the two furthest points
CentroidDistance between cluster centroids
Group averageAverage of all pairwise distances

Strengths: Deterministic, multiple clustering versions, no need to specify , can create arbitrary cluster shapes.

Weaknesses: Does not scale well to large datasets.