machine learning
supervised learning
unsupervised learning
real world examples
data science

Can anyone give a real life example of supervised learning and unsupervised learning?

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

Introduction

A real-life way to understand supervised versus unsupervised learning is to compare fraud detection and customer segmentation. Supervised learning uses historical labels to predict known outcomes. Unsupervised learning finds structure in data when labels do not exist.

Supervised Learning Example: Payment Fraud Detection

A payment platform can train a model on past transactions labeled as fraud or non-fraud. Because the target label is known during training, this is supervised learning.

Typical features include transaction amount, merchant type, device fingerprint, and account behavior aggregates.

python
1from sklearn.model_selection import train_test_split
2from sklearn.ensemble import RandomForestClassifier
3from sklearn.metrics import roc_auc_score
4import numpy as np
5
6# features: amount, merchant_risk, account_age_days
7X = np.array([
8    [120.0, 0.8, 400],
9    [15.0, 0.1, 1500],
10    [890.0, 0.9, 30],
11    [42.0, 0.2, 900],
12    [510.0, 0.7, 120],
13    [18.0, 0.1, 2000],
14], dtype=float)
15
16y = np.array([1, 0, 1, 0, 1, 0])  # 1 fraud, 0 legitimate
17
18Xtr, Xte, ytr, yte = train_test_split(X, y, test_size=0.33, random_state=7)
19model = RandomForestClassifier(random_state=7)
20model.fit(Xtr, ytr)
21
22probs = model.predict_proba(Xte)[:, 1]
23print("AUC", roc_auc_score(yte, probs))

In production, output is usually a risk score used to trigger allow, challenge, or manual review decisions.

Unsupervised Learning Example: Customer Segmentation

Now consider a retailer with behavior logs but no explicit labels like premium, casual, or bargain segment. Unsupervised clustering can discover patterns.

python
1from sklearn.cluster import KMeans
2import numpy as np
3
4# features: monthly_visits, avg_basket_value
5customers = np.array([
6    [2, 18], [3, 22],
7    [8, 65], [9, 70],
8    [15, 140], [17, 155],
9], dtype=float)
10
11kmeans = KMeans(n_clusters=3, random_state=7, n_init="auto")
12cluster_ids = kmeans.fit_predict(customers)
13
14print("cluster ids", cluster_ids)
15print("centers", kmeans.cluster_centers_)

These cluster IDs are discovered structure, not ground-truth classes. Business teams interpret them and design campaigns accordingly.

How Both Methods Work Together in Real Systems

Many companies combine both approaches in one pipeline:

  1. use unsupervised clustering to discover behavior groups.
  2. train supervised models per group for churn, conversion, or risk prediction.
  3. apply policies that combine segment identity and prediction score.

This often improves outcomes because segmentation captures heterogeneity that a single global model may miss.

Evaluation Differences Matter

Supervised models are evaluated with labeled metrics such as precision, recall, AUC, and calibration.

Unsupervised models are evaluated differently:

  • cluster compactness and separation metrics
  • stability of clusters over time
  • downstream business lift from segment-based actions

Trying to score unsupervised output with supervised metrics is a common methodological error.

Data Requirements and Governance

Supervised learning needs trustworthy labels. Label leakage, delayed ground truth, or inconsistent annotation can degrade model quality quickly.

Unsupervised learning needs careful feature engineering and scale normalization. Without that, clustering may reflect feature magnitude artifacts rather than true behavioral structure.

Both methods need:

  • feature versioning
  • drift monitoring
  • retraining policy
  • clear mapping from model output to business action

Modeling without decision policy is analytics, not operational ML.

Practical Business Examples

Supervised examples:

  • email spam classifier trained from labeled spam and non-spam messages
  • credit default probability model trained from historical repayment labels
  • product defect detector trained from labeled pass and fail images

Unsupervised examples:

  • grouping web sessions by navigation behavior
  • anomaly detection in machine sensor patterns without labeled failures
  • market basket clustering for campaign personalization

These examples show that the right method depends on whether labels are available and what decision must be made.

Common Pitfalls

Treating unsupervised cluster IDs as permanent business labels can produce misleading reporting.

Using only accuracy for imbalanced supervised problems hides poor minority-class performance.

Skipping feature standardization before clustering often produces unstable segments.

Failing to connect model outputs to clear operational actions limits business value.

Summary

  • Supervised learning predicts known labels from labeled historical data.
  • Unsupervised learning discovers patterns when labels are unavailable.
  • Real products frequently use both methods in a combined pipeline.
  • Evaluation strategy must match method type and business objective.
  • Data governance and action policy are as important as model choice.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No course covers this one yet

Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.

Build my course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design