Bird
Raised Fist0
ML Pythonml~8 mins

Types of ML (supervised, unsupervised, reinforcement) in ML Python - Model Metrics & Evaluation

Choose your learning style10 modes available
Metrics & Evaluation - Types of ML (supervised, unsupervised, reinforcement)
Which metric matters for this concept and WHY

Each type of machine learning uses different metrics because they solve different problems.

  • Supervised learning: We know the right answers, so metrics like accuracy, precision, recall, and F1 score tell us how well the model predicts.
  • Unsupervised learning: No right answers are given, so we use metrics like silhouette score or reconstruction error to see how well the model groups or represents data.
  • Reinforcement learning: The model learns by trying actions and getting rewards, so we measure total reward or average reward over time to see if it learns good behavior.

Choosing the right metric helps us know if the model is learning what we want.

Confusion matrix or equivalent visualization (ASCII)

Confusion matrix applies mainly to supervised learning classification:

      | Predicted Positive | Predicted Negative |
      |--------------------|--------------------|
      | True Positive (TP)  | False Positive (FP) |
      | False Negative (FN) | True Negative (TN)  |
    

For unsupervised learning, we use cluster plots or silhouette scores instead.

For reinforcement learning, we track reward over episodes, shown as:

      Episode 1: Reward = 5
      Episode 2: Reward = 7
      Episode 3: Reward = 10
      ...
    
Precision vs Recall tradeoff with concrete examples

This tradeoff mainly applies to supervised classification:

  • High precision, low recall: The model is very sure when it says "yes" but misses many actual positives. Example: Spam filter that rarely marks good emails as spam but misses some spam emails.
  • High recall, low precision: The model finds most positives but also marks many negatives as positive. Example: Cancer detector that catches almost all cancer cases but sometimes flags healthy people.

Choosing which to prioritize depends on the problem's cost of mistakes.

What "good" vs "bad" metric values look like for this use case
  • Supervised learning: Good accuracy or F1 score close to 1 means the model predicts well. Bad values near 0.5 or lower mean poor predictions.
  • Unsupervised learning: Good silhouette score near 1 means clear clusters. Scores near 0 or negative mean poor grouping.
  • Reinforcement learning: Good models get higher total rewards over time. If rewards stay low or do not improve, the model is not learning well.
Metrics pitfalls
  • Accuracy paradox: In supervised learning with imbalanced data, high accuracy can be misleading if the model always predicts the majority class.
  • Data leakage: When test data leaks into training, metrics look better but the model fails in real life.
  • Overfitting indicators: Very high training metrics but poor test metrics mean the model memorizes instead of learning.
  • Unsupervised metric limits: Metrics like silhouette score do not guarantee meaningful clusters; domain knowledge is needed.
  • Reinforcement learning variance: Rewards can vary a lot; averaging over many episodes is important.
Self-check question

Your supervised classification model has 98% accuracy but only 12% recall on the positive class (e.g., fraud). Is it good for production? Why or why not?

Answer: No, it is not good. The model misses 88% of fraud cases (low recall), which is dangerous. High accuracy is misleading because fraud is rare. You need to improve recall to catch more fraud.

Key Result
Different ML types require different metrics: supervised uses accuracy/precision/recall, unsupervised uses silhouette score, and reinforcement uses total reward.

Practice

(1/5)
1. Which type of machine learning uses labeled data to teach the model?
easy
A. Supervised learning
B. Unsupervised learning
C. Reinforcement learning
D. Deep learning

Solution

  1. Step 1: Understand labeled data meaning

    Labeled data means each example has a known answer or outcome.
  2. Step 2: Match learning type with labeled data

    Supervised learning uses labeled data to train models to predict outcomes.
  3. Final Answer:

    Supervised learning -> Option A
  4. Quick Check:

    Supervised = labeled data [OK]
Hint: Labeled data means supervised learning [OK]
Common Mistakes:
  • Confusing unsupervised with supervised
  • Thinking reinforcement uses labeled data
  • Mixing deep learning as a type here
2. Which of the following is the correct description of unsupervised learning?
easy
A. Learning from labeled data to predict outcomes
B. Finding patterns in data without labels
C. Learning actions to maximize rewards
D. Training deep neural networks

Solution

  1. Step 1: Recall unsupervised learning definition

    Unsupervised learning finds hidden patterns or groups in data without labels.
  2. Step 2: Match options with definition

    Finding patterns in data without labels correctly states it finds patterns without labels.
  3. Final Answer:

    Finding patterns in data without labels -> Option B
  4. Quick Check:

    Unsupervised = no labels [OK]
Hint: No labels means unsupervised learning [OK]
Common Mistakes:
  • Choosing supervised for unlabeled data
  • Confusing reinforcement with unsupervised
  • Thinking deep learning is a type of ML here
3. Consider this Python code snippet for a reinforcement learning agent:
actions = ['left', 'right', 'up', 'down']
rewards = {'left': -1, 'right': 1, 'up': 0, 'down': 0}
current_action = 'right'
reward = rewards[current_action]
print(reward)
What will be the output?
medium
A. 0
B. -1
C. null
D. 1

Solution

  1. Step 1: Identify the current action and reward mapping

    The current_action is 'right'. The rewards dictionary maps 'right' to 1.
  2. Step 2: Print the reward for 'right'

    reward = rewards['right'] equals 1, so print outputs 1.
  3. Final Answer:

    1 -> Option D
  4. Quick Check:

    Reward for 'right' = 1 [OK]
Hint: Check dictionary key for current action [OK]
Common Mistakes:
  • Confusing keys and values in dictionary
  • Printing variable before assignment
  • Assuming default reward 0
4. The following code is intended to perform supervised learning but has an error:
data = [([1, 2], 0), ([3, 4], 1), ([5, 6], 0)]
features, labels = zip(*data)
model = SomeModel()
model.train(features, labels)
What is the likely error?
medium
A. Features and labels are not separated correctly
B. Data format is incorrect for supervised learning
C. Model class SomeModel is undefined
D. train method should be fit instead

Solution

  1. Step 1: Check variable unpacking

    features and labels are correctly unpacked from data using zip(*data).
  2. Step 2: Identify model usage error

    SomeModel is not defined anywhere, so creating model = SomeModel() causes an error.
  3. Final Answer:

    Model class SomeModel is undefined -> Option C
  4. Quick Check:

    Undefined class causes error [OK]
Hint: Undefined classes cause errors at instantiation [OK]
Common Mistakes:
  • Assuming train method is wrong without context
  • Thinking data unpacking is incorrect
  • Ignoring missing model definition
5. You want to build a system that learns to play a game by trying moves and getting points as feedback. Which type of machine learning should you use?
hard
A. Reinforcement learning
B. Supervised learning
C. Unsupervised learning
D. Clustering

Solution

  1. Step 1: Understand the problem context

    The system learns by trying moves and receiving points (rewards) as feedback.
  2. Step 2: Match learning type to feedback-based learning

    Reinforcement learning fits because it learns actions to maximize rewards from feedback.
  3. Final Answer:

    Reinforcement learning -> Option A
  4. Quick Check:

    Learning from rewards = Reinforcement [OK]
Hint: Learning from rewards means reinforcement learning [OK]
Common Mistakes:
  • Choosing supervised because of 'learning'
  • Confusing clustering with reinforcement
  • Ignoring feedback as reward signal
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