Bird
Raised Fist0

Supervised vs Unsupervised vs Reinforcement Learning - When to Use Which

THEORYbeginnerInterview freq: high
Choose your preparation mode6 modes available
🐛
The Misguided Learning Paradigm
Started after a recent model update two weeks ago.

A recommendation system for an e-commerce platform, serving personalized product suggestions to 500k users daily.

Symptom
Model accuracy is high, but recall is consistently 0 for certain user segments.
📡
Signals
metric
Overall model accuracy on test set
0.92
metric
Recall for user segment 'new_users'
0.0
feature_importance
Feature importance for 'user_history_length'
Dropped from 0.25 to 0.01 after update
distribution
Distribution of predicted scores for 'new_users'
All scores are near 0.5
log
Training log indicating learning paradigm used
Switched from supervised to unsupervised learning
🔬
Hypotheses
The model is not learning effectively for new users due to the learning paradigm used.
Recall for user segment 'new_users' is 0.0Training log indicating learning paradigm used
Verify: Check if the model was trained using unsupervised learning for a task that requires labeled data.
print(training_log['learning_paradigm'])
Feature 'user_history_length' is crucial for new users, and its importance dropped significantly.
Feature importance for 'user_history_length' dropped
Verify: Analyze the feature importance before and after the update.
feature_importance.plot(kind='bar')
🎯
Root Cause
The model was mistakenly switched to unsupervised learning, which is inappropriate for the task requiring labeled data.

A misconfiguration during the model update led to the use of an unsupervised learning algorithm instead of the required supervised learning approach.

🔧
Fix Strategy
ImmediateRollback to the previous supervised learning model version.
Short-termReconfigure the model to use supervised learning with labeled data.
Long-termImplement a validation step in the deployment pipeline to ensure the correct learning paradigm is used.
🐍
Python Fix
Python
model = SupervisedLearningModel()
model.train(labeled_data)
model.save('correct_model_version')
✗
Common Wrong Diagnoses
▼ Show
The model is overfitting to the training data.
Why candidates think this: High accuracy might suggest overfitting.
Why wrong: Overfitting would not cause recall to be zero for a specific segment.
The feature 'user_history_length' is not important.
Why candidates think this: Its importance dropped significantly.
Why wrong: The drop in importance is a result of the unsupervised learning misconfiguration.
📊
Monitoring to Add
  • Alert on recall drop below a threshold for key user segments.
  • Monitor feature importance changes post-deployment.
  • Log and review learning paradigm configurations before deployment.
📋
Process Change

Introduce a checklist for model configuration verification before deployment.

🏗️
Architectural Change

Design the system to automatically validate the learning paradigm against the task requirements.

💡
Key Insight
Choosing the wrong learning paradigm can lead to misleadingly high overall metrics while failing specific segments.

Practice

(1/5)
1. In the context of Convolutional Neural Networks, what is the primary purpose of pooling layers?
easy
A. To reduce the spatial dimensions of the feature maps
B. To increase the size of the feature maps
C. To increase the number of channels in the feature maps
D. To apply non-linear activation functions

Solution

  1. Step 1: Understand pooling layers

    Pooling layers are used to reduce the spatial dimensions of feature maps, which helps in reducing computation and controlling overfitting.
  2. Step 2: Eliminate wrong options

    To increase the size of the feature maps is incorrect because pooling reduces size, not increases it. To increase the number of channels in the feature maps is incorrect as pooling doesn't change the number of channels. To apply non-linear activation functions is incorrect because pooling doesn't apply non-linear activations.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Pooling reduces spatial dimensions. [OK]
Hint: Pooling reduces spatial dimensions. [OK]
Common Mistakes:
2. In the context of K-Nearest Neighbors, what is the 'curse of dimensionality'?
easy
A. The model's complexity decreases with more dimensions.
B. The model becomes more accurate as dimensions increase.
C. The model requires less data as dimensions increase.
D. Distance metrics become less meaningful as dimensions increase.

Solution

  1. Step 1: Understand the curse of dimensionality

    As dimensions increase, the volume of the space increases exponentially, making data sparse.
  2. Step 2: Eliminate wrong options

    The model becomes more accurate as dimensions increase. is incorrect because accuracy typically decreases. The model requires less data as dimensions increase. is wrong because more data is needed. The model's complexity decreases with more dimensions. is incorrect as complexity often increases.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    High dimensions dilute distance meaning. [OK]
Hint: High dimensions dilute distance meaning. [OK]
Common Mistakes:
3. What will be the output shape of the following PyTorch code snippet?
import torch
rnn = torch.nn.RNN(input_size=10, hidden_size=20, num_layers=2)
input = torch.randn(5, 3, 10)
h0 = torch.randn(2, 3, 20)
output, hn = rnn(input, h0)
print(output.shape)
easy
A. (5, 3, 10)
B. (3, 5, 20)
C. (2, 3, 20)
D. (5, 3, 20)

Solution

  1. Step 1: Understand RNN output shape.

    The output shape of an RNN is (seq_len, batch, hidden_size).
  2. Step 2: Apply to the given code.

    Here, seq_len=5, batch=3, hidden_size=20, so the output shape is (5, 3, 20).
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    RNN output: (seq_len, batch, hidden_size). [check]
Hint: RNN output: (seq_len, batch, hidden_size). [check]
Common Mistakes:
4. In the context of high-dimensional data, which of the following is a primary reason why the curse of dimensionality affects nearest neighbor algorithms?
easy
A. Distances between points become less meaningful as dimensions increase.
B. High-dimensional data increases the risk of overfitting.
C. High-dimensional data requires more computational resources.
D. High-dimensional data leads to more complex decision boundaries.

Solution

  1. Step 1: Understand the curse of dimensionality.

    In high dimensions, the distance between points becomes less informative.
  2. Step 2: Eliminate wrong options.

    High-dimensional data increases the risk of overfitting. is about overfitting, not distance. High-dimensional data requires more computational resources. is about computation, not distance. High-dimensional data leads to more complex decision boundaries. is about decision boundaries, not distance.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    High dimensions dilute distance meaning. [OK]
Hint: High dimensions dilute distance meaning. [OK]
Common Mistakes:
5. In a multilingual context, how can you adapt Word2Vec embeddings to handle multiple languages effectively?
hard
A. Use a multilingual BERT model instead of Word2Vec.
B. Train separate Word2Vec models for each language and concatenate the embeddings.
C. Translate all text to a single language before training Word2Vec.
D. Use a shared vocabulary across languages and train a single Word2Vec model.

Solution

  1. Step 1: Evaluate multilingual strategies

    Multilingual BERT is designed to handle multiple languages effectively, unlike Word2Vec.
  2. Step 2: Eliminate wrong options

    Train separate Word2Vec models for each language and concatenate the embeddings. doesn't capture cross-lingual semantics. Use a shared vocabulary across languages and train a single Word2Vec model. is impractical due to vocabulary differences. Translate all text to a single language before training Word2Vec. loses language-specific nuances.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Multilingual BERT for cross-language tasks [OK]
Hint: Multilingual BERT for cross-language tasks [OK]
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