Bird
Raised Fist0
ML Pythonml~20 mins

Types of ML (supervised, unsupervised, reinforcement) in ML Python - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
ML Types Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Identify the type of learning from a description
You have a dataset with labeled images of cats and dogs. You want the model to learn to tell cats from dogs using these labels. What type of machine learning is this?
AUnsupervised learning
BSupervised learning
CReinforcement learning
DSelf-supervised learning
Attempts:
2 left
💡 Hint
Think about whether the data has labels or not.
❓ Predict Output
intermediate
2:00remaining
Output of clustering algorithm example
What is the output of this Python code using KMeans clustering on simple 2D points?
ML Python
from sklearn.cluster import KMeans
import numpy as np
points = np.array([[1,2],[1,4],[1,0],[10,2],[10,4],[10,0]])
kmeans = KMeans(n_clusters=2, random_state=0).fit(points)
labels = kmeans.labels_
print(labels.tolist())
A[0, 0, 0, 1, 1, 1]
B[1, 1, 1, 0, 0, 0]
C[0, 1, 0, 1, 0, 1]
D[1, 0, 1, 0, 1, 0]
Attempts:
2 left
💡 Hint
Points near (1,*) will be in one cluster, points near (10,*) in another.
❓ Model Choice
advanced
1:30remaining
Choosing the right ML type for a game AI
You want to build an AI that learns to play a video game by trying moves and getting points as feedback. Which type of machine learning should you use?
ASupervised learning
BUnsupervised learning
CReinforcement learning
DSemi-supervised learning
Attempts:
2 left
💡 Hint
The AI learns by trial and error with rewards.
❓ Metrics
advanced
1:30remaining
Evaluating clustering quality
Which metric is commonly used to evaluate the quality of an unsupervised clustering model?
ACross-entropy loss
BAccuracy
CMean squared error
DSilhouette score
Attempts:
2 left
💡 Hint
This metric measures how well clusters are separated.
🔧 Debug
expert
2:30remaining
Why does this reinforcement learning code not update the policy?
Consider this simplified reinforcement learning code snippet. Why does the policy not improve after training?
ML Python
import numpy as np
policy = np.array([0.5, 0.5])
rewards = [1, -1, 1, -1]
actions = [0, 1, 0, 1]
for r, a in zip(rewards, actions):
    policy[a] += 0.1 * r
policy = policy / policy.sum()
print(policy)
APolicy probabilities can become negative causing invalid distribution
BNormalization divides by sum but sum can be zero causing error
CLearning rate 0.1 is too small to update policy noticeably
DRewards are not used to update the policy correctly
Attempts:
2 left
💡 Hint
Check if policy values remain valid probabilities after updates.

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