🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to Machine Learning Notes
Topic #5

Unsupervised Learning

Unsupervised learning finds structure in data that has no labels — no "correct answer" is provided, so the algorithm groups, compresses or otherwise organizes the data based on patterns in the features alone.

Two Main Tasks

TaskGoalExample Algorithms
ClusteringGroup similar data points togetherK-Means, Hierarchical Clustering, DBSCAN
Dimensionality ReductionCompress many features into fewer, while keeping most of the informationPCA, t-SNE, UMAP

Minimal Example — Customer Segmentation

from sklearn.cluster import KMeans
import numpy as np

# annual_spend (in thousands), visits_per_month — no labels given
X = np.array([[2, 1], [3, 1], [40, 8], [42, 9], [41, 7]])

model = KMeans(n_clusters=2, random_state=42, n_init=10)
labels = model.fit_predict(X)
print(labels)

Expected output: something like [0 0 1 1 1] — the algorithm separated low-spend/low-visit customers from high-spend/high-visit customers purely from the numbers, with no "customer type" label ever provided.

Why It's Harder to Evaluate

Without ground-truth labels, there's no single "accuracy" to compute. Evaluation relies on internal metrics like silhouette score, or on whether the resulting groups make business sense to a human reviewer.

Practical Use Cases

  • Customer segmentation for targeted marketing
  • Anomaly/fraud detection (points that don't fit any cluster)
  • Compressing high-dimensional data for visualization or as input to another model
  • Topic discovery in a collection of documents

Advantages

  • Doesn't require expensive labeled data
  • Can reveal structure a human analyst wouldn't have thought to look for

Limitations

  • No objective "correctness" measure — results need domain judgment to interpret
  • Sensitive to feature scaling and the choice of number of clusters (see elbow method)

Common Mistakes

  • Running clustering on unscaled features — a feature ranging 0–100000 will dominate distance calculations over one ranging 0–1; always apply feature scaling first.
  • Assuming clusters found by an algorithm automatically correspond to meaningful real-world categories — they need to be validated against business context.

Interview Relevance

Q: "How would you evaluate a clustering result with no ground truth?" Use internal metrics (silhouette score, within-cluster sum of squares) alongside a domain-expert sanity check of what the clusters actually represent.

Practice Question

You're given transaction data with no fraud labels. Describe how you'd use unsupervised learning to flag potentially fraudulent transactions.

Want to go beyond the notes?

Join CodingNow 2.0's Machine Learning course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Unsupervised Learning – FAQs

Quick answers about learning Unsupervised Learning in Machine Learning.

This free note from CodingNow 2.0 explains Unsupervised Learning in Machine Learning — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Machine Learning topic on CodingNow 2.0, including Unsupervised Learning, is 100% free with no signup required.
With focused practice, most students grasp Unsupervised Learning in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now