Dung (Donny) Nguyen

Senior Software Engineer

Unsupervised Learning

Introduction

Unsupervised learning is a branch of machine learning where a model learns from data that has no labels. Unlike supervised learning, there are no correct answers provided during training. Instead, the model explores the data on its own to discover hidden patterns, structures, and relationships.

The name “unsupervised” reflects the absence of a teacher. There is no known output to compare against, so the algorithm must find meaning in the data by itself. This makes unsupervised learning especially valuable when labeled data is scarce, expensive, or impossible to obtain.


How Unsupervised Learning Works

Because there are no labels, unsupervised learning focuses on the structure of the input data itself. The general process looks like this:

  1. Collect unlabeled data: Gather a dataset with input features but no target values.
  2. Preprocess the data: Clean, normalize, and scale the features so distances and relationships are meaningful.
  3. Choose a model: Select an algorithm suited to the goal, such as clustering or dimensionality reduction.
  4. Fit the model: Let the algorithm analyze the data to find groups, patterns, or a compact representation.
  5. Interpret the results: Examine the discovered structure and evaluate whether it is useful.

Instead of minimizing prediction error against known labels, unsupervised algorithms optimize objectives like grouping similar points together, maximizing variance, or reconstructing the original data from a compressed form.


Types of Unsupervised Learning

Unsupervised learning covers several related tasks. The most common are clustering, dimensionality reduction, and association.

Clustering

Clustering groups data points so that items in the same group are more similar to each other than to those in other groups. The algorithm defines the groups without any predefined categories.

Examples:

Dimensionality Reduction

Dimensionality reduction compresses data with many features into fewer dimensions while preserving as much important information as possible. This makes data easier to visualize, faster to process, and less prone to noise.

Examples:

Association

Association discovers rules that describe how items relate to one another, often in transaction data. It finds items that frequently occur together.

Examples:


Common Unsupervised Learning Algorithms

Different algorithms suit different unsupervised tasks.


Evaluating Unsupervised Models

Evaluation is harder than in supervised learning because there are no ground-truth labels to compare against. Instead, we rely on internal measures of quality and, when available, external validation.

Clustering metrics:

Dimensionality reduction metrics:

When some labels are available, external metrics like the Adjusted Rand Index or Normalized Mutual Information can compare discovered clusters against known categories.


Choosing the Number of Clusters

Many clustering algorithms require you to specify how many groups to find. Two common techniques help make this choice:


A Practical Example

Here is a simple clustering example using scikit-learn in Python:

from sklearn.datasets import load_iris
from sklearn.preprocessing import StandardScaler
from sklearn.cluster import KMeans
from sklearn.metrics import silhouette_score

# Load an unlabeled dataset (labels are ignored)
X, _ = load_iris(return_X_y=True)

# Scale features so distances are meaningful
X_scaled = StandardScaler().fit_transform(X)

# Fit an unsupervised clustering model
model = KMeans(n_clusters=3, random_state=42, n_init=10)
clusters = model.fit_predict(X_scaled)

# Evaluate cluster quality without labels
print("Silhouette score:", silhouette_score(X_scaled, clusters))

This example scales the Iris features, groups them into three clusters with k-means, and evaluates the clustering quality using the silhouette score, all without using any labels.


Supervised vs. Unsupervised Learning

It helps to understand unsupervised learning in contrast to supervised learning:

Aspect Supervised Learning Unsupervised Learning
Data Labeled Unlabeled
Goal Predict outputs Discover structure
Examples Classification, regression Clustering, dimensionality reduction
Feedback Uses known answers No known answers
Evaluation Straightforward with metrics Harder, often indirect

Unsupervised learning is the right choice when you have no labels and want to explore, summarize, or find structure in your data.


Common Use Cases

Unsupervised learning powers many real-world applications:


Summary

Unsupervised learning finds hidden patterns in unlabeled data. Its main tasks are clustering (grouping similar items), dimensionality reduction (compressing data while preserving structure), and association (discovering relationships between items). Because there are no ground-truth labels, evaluation relies on internal quality measures like the silhouette score and explained variance.

Unsupervised learning is essential when labeled data is unavailable or expensive, and it often serves as a first step in understanding data before applying other techniques. Mastering it alongside supervised learning gives an AI engineer a complete toolkit for tackling a wide range of real-world problems.