Coding Now – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 9667708830
Back to Machine Learning Notes
Topic #105

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.

Related ML Notes

Want to go beyond the notes?

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

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →