Skip to main content
onepocketML

Unsupervised Learning

Unsupervised Learning

Unsupervised learning is machine learning without an answer key: the model receives data with no predefined labels and tries to discover structure on its own.

beginner · 11 min read

Lesson content

The previous lesson covered supervised learning, where every training example comes with a known correct answer. Unsupervised learning is what you reach for when that answer key does not exist. The model receives data without predefined labels and tries to discover structure in it on its own.

Definition

Unsupervised learning

Giving a model a pile of unlabeled data and letting it find patterns, groups, or structure in that data by itself, with no known correct answer to check against.

Formal definition

A machine learning approach in which a model is given data with no labeled outputs and must infer structure, such as natural groupings or a simpler underlying representation, directly from the data's own patterns.

Sorting a mixed drawer of buttons with no labels

Hand someone a drawer of mixed buttons with no size chart and no category labels, and ask them to organize it.

They will start grouping similar buttons together, perhaps by color, then by size, without ever being told what the correct categories are. Nobody handed them an answer key. They found the structure themselves.

That is unsupervised learning: no label says which button belongs where, only the buttons' own similarities to guide the grouping.

Notice what the analogy also implies. A second person might sort the same drawer by material or by number of holes, and they would not be wrong either. Unsupervised structure is found, but it is not unique.

The same points twice. Clustering proposes a grouping; nothing in the data says the grouping is right, so judging it is your job.
Why would you ever want a model to run without labels?

Because for a huge amount of real-world data, labels simply do not exist or are too expensive to collect. Nobody has manually tagged "which customers are similar to each other" or "which of these 10,000 news articles cover the same topic", unsupervised learning finds that structure directly from the data instead of requiring someone to label it first.

If there is no known correct answer, how do you know the result is any good?

You check whether the structure the model found is useful and makes sense.

Do the groups it discovered actually separate customers who behave differently? Does the simplified version of the data still capture what mattered in the original? Would a different random seed give broadly the same answer?

There is no single correct grouping to compare against, so there is no accuracy score. Internal measures such as the silhouette score help, but they only tell you whether the groups are tight and separated, not whether they are meaningful.

So evaluating unsupervised learning leans far more on human judgment and downstream usefulness than supervised learning does. The honest test is often whether anyone can act on the result.

Example

Grouping customers with no predefined segments

A retailer has purchase history for 10,000 customers but no existing labels like "budget shopper" or "frequent buyer", those categories do not exist yet. An unsupervised model can group customers by similarity in spending amount, purchase frequency and product categories, revealing natural segments the retailer can then name and act on.

Customer purchase data with no predefined segment labels
Avg. order ($)Orders/monthCategories bought
1450.51
2263
1852
2100.31
3074

There is no "segment" column here, no known right answer for any row. The model's job is to notice that rows 2, 3 and 5 look similar to each other and rows 1 and 4 look similar to each other and group them accordingly.

Goal

Clustering
Group similar examples together
Dimensionality reduction
Compress many columns into fewer, while keeping what matters

Output

Clustering
A group assignment for each example
Dimensionality reduction
A smaller set of new, computed columns for each example

Example

Clustering
Grouping customers into spending segments
Dimensionality reduction
Compressing 50 survey questions into 2 summary scores

Answers the question

Clustering
"Which examples are similar to each other?"
Dimensionality reduction
"Which few dimensions capture most of the variation?"

Both branches start from the same place, data with no labels, and they solve different problems.

Clustering sorts the rows into groups of similar ones, like the button drawer. It answers "which of these belong together?"

Dimensionality reduction works on the columns instead. It shrinks many features down to a few that still capture most of what matters, which helps when you have far more features than you can look at, plot, or feed to a model without it overfitting.

They combine often: reduce first so the data is easier to cluster, then cluster, then plot the clusters in the reduced space to see them.

customer_segments.py
from sklearn.cluster import KMeans# No label column anywhere — just three unlabeled features per customerX = [[145, 0.5, 1], [22, 6, 3], [18, 5, 2], [210, 0.3, 1], [30, 7, 4]]model = KMeans(n_clusters=2)model.fit(X)# The model assigns each customer to a group it discovered on its ownprint(model.labels_)
from sklearn.cluster import KMeans

KMeans is one of the simplest clustering algorithms, it groups examples by how close together they are.

# No label column anywhere — just three unlabeled features per customer
X = [[145, 0.5, 1], [22, 6, 3], [18, 5, 2], [210, 0.3, 1], [30, 7, 4]]

X has no matching y. There is nothing to fit against, because there is no known correct grouping to learn from.

model = KMeans(n_clusters=2)

n_clusters=2 tells the model to look for two groups, a choice a person makes, since there is no label to reveal how many groups actually exist.

model.fit(X)

.fit(X) takes only X, compare this to the supervised examples in earlier lessons, which always called .fit(X, y).

print(model.labels_)

model.labels_ holds the group number the model assigned each customer, a label the model invented, not one it was given.

Cluster

A group of examples the model decided are similar to each other.

Clusters are the output of clustering algorithms and the whole reason unsupervised grouping is useful: they turn raw data into named, actionable segments.

Dimensionality reduction

Compressing many columns of data into a smaller number of columns that still capture most of what mattered.

It makes very wide datasets (hundreds of columns) easier to visualize, store and feed into other models.

Unlabeled data

Data where no column tells you the "correct answer" for each row.

It is the starting condition every unsupervised learning problem shares and the reason supervised techniques cannot be applied directly.

When to use

  • You want to discover natural groupings in data with no predefined categories, like customer segments
  • You have far more columns than you can reasonably analyze or plot and want to compress them down
  • Labels do not exist yet and are too expensive or slow to collect before you need results

When to avoid

  • You already know exactly what you are trying to predict and have labeled examples for it. That is a supervised learning problem instead
  • You need a guaranteed, verifiable correct answer for each prediction, since there is no answer key to check against
  • The number of groups or dimensions genuinely matters and cannot be chosen through judgment or experimentation

Expecting unsupervised learning to tell you what each discovered group "means."

The model only finds that groups exist and which examples belong to which, a person still has to look at each group and decide what it represents, like naming a segment "frequent budget shoppers."

Assuming there is one single correct number of clusters for any dataset.

The right number of groups usually depends on what is useful for your purpose, not a fact the data reveals on its own, different reasonable choices can all be defensible.

Trying to use accuracy, the way you would for a classifier, to judge an unsupervised model.

There is no known correct label to compare against, so unsupervised results are judged by whether the structure found is useful and sensible, not by a percent-correct score.

Key takeaway

  • Unsupervised learning finds structure in data that has no predefined labels.
  • Clustering groups similar examples together. Dimensionality reduction compresses many columns into fewer.
  • Because there is no known correct answer, evaluating results relies more on human judgment than on a simple accuracy score.
  • Reach for it when labels do not exist yet, or when the goal is discovering structure rather than predicting a known answer.

Finished this lesson?

Guest progress is saved on this device.

Unsupervised Learning | OnePocketML