Bird
Raised Fist0

Supervised vs Unsupervised vs Reinforcement Learning - When to Use Which

THEORYbeginnerInterview freq: high
Choose your preparation mode6 modes available
🤖
Supervised vs Unsupervised vs Reinforcement Learning - When to Use Which
Choosing the right learning paradigm for your problem
theorybeginnerFreq: highML Foundations
Prerequisites:Why Machine Learning Exists
💡
Why It Exists

Different types of learning paradigms were developed to address specific types of problems: supervised learning for labeled data where the goal is prediction, unsupervised learning for discovering patterns in unlabeled data, and reinforcement learning for decision-making tasks where an agent learns by interacting with an environment.

📖
What It Is

Supervised learning uses labeled data to train models to make predictions. Unsupervised learning finds hidden patterns in unlabeled data. Reinforcement learning trains agents to make sequences of decisions by rewarding desired behaviors.

∑
Math Intuition
In supervised learning, the loss function quantifies the difference between predicted and actual values, guiding the model to minimize this error. In unsupervised learning, algorithms like k-means minimize intra-cluster variance to group similar data points. Reinforcement learning uses a reward function to evaluate actions, encouraging the agent to maximize cumulative rewards over time.
⚙️
Core Mechanism

Supervised learning maps inputs to outputs using labeled data. Unsupervised learning identifies structure in data without labels. Reinforcement learning optimizes actions through trial and error.

📋
Step by Step
  1. Supervised: Collect labeled data, choose a model, train the model, evaluate performance.
  2. Unsupervised: Collect data, choose a model, train the model to find patterns, evaluate the discovered patterns.
  3. Reinforcement: Define the environment, set rewards, train the agent through interactions, evaluate the policy.
🎯
Intuition
Think of supervised learning as a teacher grading homework, unsupervised learning as a detective finding clues, and reinforcement learning as a gamer learning strategies through gameplay.
🐍
Python Example
Python
import numpy as np
from sklearn.linear_model import LinearRegression

# Supervised Learning Example
X = np.array([[1, 2], [2, 3], [3, 4]])
y = np.array([3, 5, 7])
model = LinearRegression().fit(X, y)
prediction = model.predict(np.array([[4, 5]]))
print(prediction)  # output: [9.]
✅
When It Works
  • Supervised learning is ideal when you have a large, labeled dataset and a clear prediction goal.
  • Unsupervised learning is suitable when you want to explore data structure without predefined labels.
  • Reinforcement learning excels in environments where an agent can learn from interactions and feedback.
⚠️
When It Breaks
  • Supervised learning struggles with insufficient labeled data, leading to overfitting or underfitting.
  • Unsupervised learning can fail when data lacks inherent structure, resulting in meaningless clusters.
  • Reinforcement learning can be inefficient in environments with sparse rewards, causing slow learning.
⇄
vs Semi-supervised Learning
Use This When
Use supervised learning when you have ample labeled data and need precise predictions.
Use Alternative When
Use semi-supervised learning when labeled data is scarce but unlabeled data is abundant.
🎯
Interview Angles
  • Interviewer asks: 'How would you approach a problem with limited labeled data?' → testing understanding of when to use semi-supervised or unsupervised learning.
  • Interviewer asks: 'Explain how reinforcement learning differs from supervised learning.' → assessing knowledge of learning paradigms and their applications.
  • Interviewer asks: 'What challenges might you face using unsupervised learning?' → evaluating awareness of potential pitfalls and limitations.
⚠️
Common Mistakes
📌
Summary
  • Supervised learning requires labeled data and is used for prediction tasks.
  • Unsupervised learning explores data without labels to find hidden patterns.
  • Reinforcement learning involves agents learning optimal actions through interaction and feedback.

Practice

(1/5)
1. In which scenario is normalization preferred over standardization?
easy
A. When the data is on different scales and not Gaussian.
B. When the data contains outliers.
C. When the data follows a Gaussian distribution.
D. When the model is sensitive to variance.

Solution

  1. Step 1: Understand the purpose of normalization.

    Normalization scales the data to a range of [0, 1] and is useful when data is on different scales.
  2. Step 2: Eliminate wrong options.

    When the data follows a Gaussian distribution. is incorrect because standardization is preferred for Gaussian distributions. When the data contains outliers. is incorrect because normalization is sensitive to outliers. When the model is sensitive to variance. is incorrect because standardization handles variance better.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Normalize for non-Gaussian, different scales. [OK]
Hint: Normalize for non-Gaussian, different scales. [OK]
Common Mistakes:
2. In a CI/CD pipeline for ML, which component is responsible for automatically retraining models when new data is available?
easy
A. Continuous integration server
B. Data pipeline
C. Model registry
D. Version control system

Solution

  1. Step 1: Identify the role of each component.

    Version control manages code, CI server automates testing, model registry stores models, data pipeline handles data flow.
  2. Step 2: Eliminate wrong options.

    Version control (A) and CI server (B) don't handle data. Model registry (C) stores models, not data. Data pipeline (D) triggers retraining with new data.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Data pipeline triggers retraining. [OK]
Hint: Data pipeline triggers retraining. [OK]
Common Mistakes:
3.
import numpy as np
from sklearn.model_selection import cross_val_score
from sklearn.tree import DecisionTreeClassifier

X = np.array([[1, 2], [3, 4], [5, 6], [7, 8]])
y = np.array([0, 1, 0, 1])

model = DecisionTreeClassifier()
scores = cross_val_score(model, X, y, cv=2)
print(scores)
What does this code output?
easy
A. An array of two accuracy scores, each representing a fold.
B. An error because the dataset is too small for cross-validation.
C. A single accuracy score for the entire dataset.
D. An array of four accuracy scores, one for each data point.

Solution

  1. Step 1: Understand cross-validation output

    Cross-validation with cv=2 splits the data into two folds, returning an array of two scores.
  2. Step 2: Eliminate wrong options

    An error because the dataset is too small for cross-validation. is incorrect because the code runs without error. A single accuracy score for the entire dataset. is incorrect because cross-validation returns multiple scores. An array of four accuracy scores, one for each data point. is incorrect because the number of scores equals the number of folds, not data points.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Cross-validation returns scores per fold. [OK]
Hint: Cross-validation returns scores per fold. [OK]
Common Mistakes:
4. When choosing between Word2Vec and BERT for a text classification task, which scenario makes Word2Vec a better choice?
medium
A. When the task requires understanding context-dependent meanings.
B. When computational resources are limited and speed is crucial.
C. When the task involves understanding nuanced language semantics.
D. When the dataset is small and requires deep contextual understanding.

Solution

  1. Step 1: Compare Word2Vec and BERT

    Word2Vec is less resource-intensive and faster than BERT, which is beneficial when resources are limited.
  2. Step 2: Eliminate wrong options

    Options A, C, and D require deep contextual understanding, which BERT handles better than Word2Vec.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Word2Vec for speed, BERT for context [OK]
Hint: Word2Vec for speed, BERT for context [OK]
Common Mistakes:
5. When choosing between a Graph Convolutional Network (GCN) and a Graph Attention Network (GAT) for a task with highly heterogeneous node importance, which is more appropriate and why?
medium
A. GCN, because it is simpler and faster for all graph tasks.
B. GAT, because it can assign different importance to different nodes.
C. GCN, because it uses attention mechanisms to focus on important nodes.
D. GAT, because it is always better than GCN in every scenario.

Solution

  1. Step 1: Identify the task requirement

    Highly heterogeneous node importance suggests the need for attention mechanisms.
  2. Step 2: Compare GCN and GAT

    GAT uses attention to weigh node importance, unlike GCN.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Use GAT for node importance heterogeneity. [check]
Hint: Use GAT for node importance heterogeneity. [check]
Common Mistakes:
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard