In our guide to supervised learning, we saw how models learn from labelled data, meaning examples where the correct answer is already known. But most of the data in the real world has no labels at all: customer transactions, website clicks, sensor readings, server logs, documents and images. Labelling all of it would take enormous time and money. This is where unsupervised learning comes in. In this article, we’ll explain what unsupervised learning is, how it works, the main techniques and algorithms, and how to build your first model.
What Is Unsupervised Learning?
Unsupervised learning is a type of machine learning where a model learns from unlabelled data, finding hidden patterns, groups or structure on its own without being told what the correct answer is.
It’s called “unsupervised” because there is no teacher providing answers. Imagine being handed a box of thousands of mixed photos and asked to sort them into piles. Nobody tells you what the piles should be, but you naturally group beaches with beaches, birthdays with birthdays and pets with pets. Unsupervised learning works the same way: it looks at the data and organises it based on similarities and differences.
Key Terms to Know
| Term | Meaning | Example (online store customers) |
|---|---|---|
| Unlabelled data | Data with inputs but no correct answers attached | Purchase history of 50,000 customers |
| Features | The input information the model uses | Annual spend, visits per month, average basket size |
| Cluster | A group of data points that are similar to each other | “Frequent big spenders” |
| Centroid | The centre point of a cluster | The “average” customer in a group |
| Dimension | A single feature or column in the data | Each attribute tracked per customer |
| Anomaly / Outlier | A data point that doesn’t fit the normal pattern | An account with sudden, unusual spending |
How Unsupervised Learning Works
Unlike supervised learning, there is no “correct answer” to check against. Instead, the process is about exploring the data and interpreting what the model finds.
- Collect data. Gather the raw data you want to understand. No labels are needed.
- Prepare the data. Clean it, handle missing values and scale the features so that no single column dominates (for example, income in thousands vs. age in years).
- Choose a technique. Decide what you want to discover: groups (clustering), simpler representations (dimensionality reduction), unusual cases (anomaly detection) or relationships between items (association rules).
- Train the model. The algorithm measures how similar or different data points are and organises them into structure.
- Interpret and validate. Inspect the results, check them with quality metrics and domain knowledge, and give them meaning, such as naming each customer segment.
The Main Types of Unsupervised Learning
1. Clustering: Finding Groups
Clustering groups similar data points together, so that items in the same cluster are more alike than items in different clusters.
- Segmenting customers by buying behaviour
- Grouping news articles or support tickets by topic
- Organising photos by visual similarity
- Identifying regions with similar sales patterns
2. Dimensionality Reduction: Simplifying Data
Real-world datasets can have hundreds or thousands of features. Dimensionality reduction compresses them into a smaller number of meaningful features while keeping the most important information.
- Visualising complex data in 2D or 3D charts
- Speeding up other machine learning models
- Removing noise and redundant features
- Compressing images and signals
3. Anomaly Detection: Spotting the Unusual
By learning what “normal” looks like, the model can flag data points that don’t fit the pattern.
- Detecting fraudulent credit card transactions
- Spotting faulty machines from sensor readings (predictive maintenance)
- Identifying suspicious network activity in cybersecurity
4. Association Rules: Finding Relationships
Association rule learning discovers items that frequently occur together. The classic example is market basket analysis: customers who buy bread and butter often buy milk too. This powers “frequently bought together” suggestions in online stores.
Quick tip: If you want to find groups, use clustering. If you want to simplify data, use dimensionality reduction. If you want to find what doesn’t belong, use anomaly detection. If you want to find what goes together, use association rules.
Popular Unsupervised Learning Algorithms
| Algorithm | Type | How it works (in simple terms) | Good for |
|---|---|---|---|
| K-Means | Clustering | Splits data into K groups around central points | Customer segmentation |
| Hierarchical Clustering | Clustering | Builds a tree of clusters by merging similar groups step by step | Exploring how groups relate |
| DBSCAN | Clustering | Groups points in dense areas and marks isolated points as noise | Irregular-shaped clusters, location data |
| PCA (Principal Component Analysis) | Dimensionality reduction | Combines features into fewer new ones that keep the most variation | Simplifying data, speeding up models |
| t-SNE / UMAP | Dimensionality reduction | Maps high-dimensional data into 2D or 3D while keeping similar points close | Visualising complex data |
| Isolation Forest | Anomaly detection | Isolates unusual points, which are easier to separate from the rest | Fraud and fault detection |
| Apriori | Association rules | Finds item combinations that frequently appear together | Market basket analysis |
| Autoencoders | Dimensionality reduction / anomaly detection | Neural networks that learn to compress and rebuild data | Images, complex anomaly detection |
As with supervised learning, there’s no single “best” algorithm. K-Means and PCA are great starting points because they’re fast, simple and easy to interpret.
How Do We Measure a Model’s Performance?
This is the trickiest part of unsupervised learning. Since there are no correct answers, we can’t simply calculate accuracy. Instead, we use a combination of metrics and human judgement.
Metrics for clustering
- Silhouette score: Measures how well each point fits its own cluster compared to other clusters. Ranges from -1 to 1 (higher is better).
- Inertia (within-cluster sum of squares): How tightly packed the clusters are. Lower is tighter, but it always decreases as you add more clusters.
- Elbow method: Plot inertia for different numbers of clusters and look for the “elbow” where adding more clusters stops giving much improvement.
Metrics for dimensionality reduction
- Explained variance: How much of the original information is kept after reducing the features. For example, keeping 95% of the variance with 10 features instead of 100.
Metrics only tell part of the story. A clustering result is only valuable if the groups make sense for the business. That’s why domain experts should always review and interpret the results.
Choosing the Right Number of Clusters
A common challenge with algorithms like K-Means is that you must decide the number of clusters (K) in advance:
- Too few clusters: Different groups get merged together and important distinctions are lost, like putting budget shoppers and luxury shoppers in the same segment.
- Too many clusters: Natural groups get split into tiny, meaningless pieces that are hard to act on.
The goal is a number of clusters that is both statistically sound and practically useful. Use the elbow method and silhouette score as a guide, then check whether the resulting groups make sense to the people who will use them.
Build Your First Unsupervised Learning Model
Here’s a complete example in Python using scikit-learn. We’ll take the same iris flower dataset from our supervised learning guide, but this time throw away the species labels and let K-Means discover the groups on its own.
from sklearn.datasets import load_iris
from sklearn.preprocessing import StandardScaler
from sklearn.cluster import KMeans
from sklearn.metrics import silhouette_score
# 1. Load the data, but ignore the labels (unsupervised!)
X, _ = load_iris(return_X_y=True)
# 2. Scale the features so each one contributes equally
X_scaled = StandardScaler().fit_transform(X)
# 3. Try different numbers of clusters and compare silhouette scores
for k in range(2, 7):
kmeans = KMeans(n_clusters=k, random_state=42, n_init=10)
clusters = kmeans.fit_predict(X_scaled)
print(f"K={k}: silhouette score = {silhouette_score(X_scaled, clusters):.2f}")
# 4. Train the final model with 3 clusters and see the group sizes
model = KMeans(n_clusters=3, random_state=42, n_init=10)
clusters = model.fit_predict(X_scaled)
print("Flowers in each cluster:", [list(clusters).count(c) for c in range(3)])
In just a few lines, this follows the full unsupervised learning process: load data, prepare it, train, evaluate and interpret. Interestingly, the silhouette score is often highest at K=2, even though there are three real species. Two of the species are very similar, so the data naturally forms two clear groups. This is a great reminder that metrics guide the decision, but domain knowledge makes it.
Real-World Applications
- Retail & E-commerce: Customer segmentation, “frequently bought together” recommendations, product grouping.
- Banking & Finance: Fraud and money-laundering detection, grouping customers by risk behaviour.
- Healthcare: Grouping patients with similar symptoms, discovering subtypes of diseases from genetic data.
- Manufacturing: Predictive maintenance by detecting unusual machine behaviour.
- Cybersecurity: Detecting unusual network traffic and potential intrusions.
- Search & AI: Organising documents by topic and learning embeddings that power semantic search and AI chatbots.
Supervised vs. Unsupervised Learning
| Supervised Learning | Unsupervised Learning | |
|---|---|---|
| Data | Labelled (answers known) | Unlabelled (no answers) |
| Goal | Predict a known outcome | Discover hidden patterns and structure |
| Main tasks | Classification, regression | Clustering, dimensionality reduction, anomaly detection, association rules |
| Evaluation | Clear metrics (accuracy, RMSE) | Harder; needs metrics plus human judgement |
| Example | Is this email spam? | What types of customers do we have? |
Advantages and Limitations
Advantages
- No labelling needed, so you can work with the data you already have.
- Discovers patterns and groups that humans may not have thought to look for.
- Useful as a first step to explore and understand a new dataset.
- Its outputs (clusters, reduced features) can improve supervised models.
Limitations
- Harder to evaluate. Without correct answers, it’s difficult to know if the results are “right”.
- Results need interpretation. The model finds groups, but people have to decide what they mean and whether they’re useful.
- Sensitive to choices. Results can change based on feature scaling, the algorithm used and settings like the number of clusters.
Conclusion
Unsupervised learning helps us make sense of the huge amounts of unlabelled data that organisations collect every day. The idea is simple: give the model data without answers, and it discovers the hidden structure on its own. Understanding clustering, dimensionality reduction and anomaly detection, along with how to evaluate and interpret results, will help you unlock insights from data you already have.
In our upcoming article, we’ll look at reinforcement learning, where models learn by trial and error, receiving rewards for good decisions.
At SciAiLabs, we build machine learning and AI solutions that help you discover hidden patterns in your data and turn them into smarter decisions. Get in touch to discuss your project.