First time studying this topic?

Launch the interactive walkthrough to discover each component, including the 3D Q-Sphere Lab & Python in Colab.

Topic 1.6

The Three Main Types of Machine Learning

Survey the three foundational pillars of ML: Supervised Learning, Unsupervised Learning, and Reinforcement Learning.

Learning Objectives

  • ✓Compare Supervised, Unsupervised, and Reinforcement Learning paradigms
  • ✓Identify typical use-cases and requirements for each learning type
  • ✓Understand semi-supervised and self-supervised hybrid methodologies

📖Let's Begin with a Story

Imagine three distinct ways a student can learn mathematics: 1. With a Tutor (Supervised): The student solves 500 practice problems. For every problem, the teacher points out the exact correct answer and marks errors. 2. Exploring Books in a Library (Unsupervised): The student walks into a library with thousands of unsorted manuscripts in unknown languages. Without any teacher, the student notices that certain books share identical symbols, themes, and bindings, organizing them into natural clusters. 3. Playing a Video Game (Reinforcement Learning): The student plays a complex puzzle game. Nobody explains the rules. When they jump into a pit, they lose a life (negative reward); when they open a chest, they gain points (positive reward). Through thousands of attempts, they discover the winning strategy.

Why Should You Learn The Three Main Types of Machine Learning?

🎯 Practical & Engineering Stakes

Why categorizing ML paradigms matters:

1. Problem scoping: When presented with a business problem, the first step is always determining: "Do we have labeled data (Supervised), unstructured data (Unsupervised), or an interactive environment (RL)?" 2. Cost estimation: Labeled data requires expensive human annotators; knowing alternative paradigms saves immense engineering cost.

What Is It?

Simple Explanation

Supervised Learning learns from examples that have correct answers attached (labeled data). Unsupervised Learning finds hidden patterns and groups in data with no answers provided (unlabeled data). Reinforcement Learning learns by trial and error through rewards and penalties in an interactive environment.

Technical Explanation

Supervised Learning maps input domain X\mathcal{X} to output space Y\mathcal{Y} using labeled pairs D={(xi,yi)}\mathcal{D} = \{(x_i, y_i)\}. Unsupervised Learning infers the underlying probability distribution p(x)p(\mathbf{x}) or latent geometric manifold from unannotated samples D={xi}\mathcal{D} = \{x_i\}. Reinforcement Learning optimizes a policy π(a∣s)\pi(a|s) to maximize expected cumulative discounted return in a Markov Decision Process (MDP).

📚 Key Terms

Supervised Learning

Simple: Training with labeled examples (input + correct answer).
Technical: Inductive inference from paired data points to minimize empirical supervisory risk.

Unsupervised Learning

Simple: Discovering natural structure or groupings without labels.
Technical: Density estimation, dimensionality reduction, or clustering without supervisory feedback.

Reinforcement Learning

Simple: Learning through interaction, trial, error, and rewards.
Technical: Optimization of sequential decision policies within an MDP framework via environmental feedback signals.

⚙️ How Does It Work?

1

Supervised Flow

Input + Label -> Loss Calculation -> Gradient Descent -> Predictive Model.

2

Unsupervised Flow

Input Only -> Distance/Density Calculation -> Centroids/Embeddings -> Structural Clustering.

3

Reinforcement Flow

State -> Action -> Environment Transition -> Reward Signal -> Policy Optimization.

🌍 Where Is It Used?

Supervised: Spam Detection

Problem: Classifying incoming emails.

Solution: Model trained on 100,000 human-marked "Spam" vs "Not Spam" emails.

Unsupervised: Customer Segmentation

Problem: Group 1 million shoppers without pre-existing labels.

Solution: K-Means clustering segments customers by purchasing velocity and basket size.

Reinforcement: AlphaGo

Problem: Mastering the ancient board game Go.

Solution: Deep RL agent played millions of self-play games to surpass all human champions.

🎯 Try It Yourself

A robotic arm learns to flip pancakes by attempting flips and receiving +10 points for landing cleanly and -10 for dropping on the floor. Which ML type is this?

Interactive activity component

🐍 Python Hands-On: Comparing Supervised vs Unsupervised in Code

See a supervised classifier and an unsupervised clusterer side-by-side on the same 2D data.

Open Colab

1Install Required Packages

For Google Colab or Jupyter notebooks, run this shell command to install the required dependencies:

Terminal / Notebook Install Commandbash
!pip install scikit-learn numpy
Packages:
scikit-learnnumpy

2Import Libraries

Import Statementspython
1from sklearn.neighbors import KNeighborsClassifier
2from sklearn.cluster import KMeans
3import numpy as np

from sklearn.neighbors import KNeighborsClassifier → Supervised classifier

from sklearn.cluster import KMeans → Unsupervised clusterer

import numpy as np → Array processing

3Demonstration Code & Logic

Python Execution Codepython
1X = np.array([[1, 2], [1, 4], [2, 2], [8, 7], [9, 8], [8, 9]])
2y = [0, 0, 0, 1, 1, 1] # Labels for supervised
3
4# 1. Supervised Learning (Uses both X and y):
5knn = KNeighborsClassifier(n_neighbors=1).fit(X, y)
6print("Supervised Prediction for [2,3]:", knn.predict([[2, 3]]))
7
8# 2. Unsupervised Learning (Uses ONLY X! No labels given!):
9kmeans = KMeans(n_clusters=2, random_state=42).fit(X)
10print("Unsupervised Cluster Assignments:", kmeans.labels_)
Step-by-Step Code Breakdown:

X = np.array([[1, 2], [1, 4], [2, 2], [8, 7], [9, 8], [8, 9]])

6 data points in 2D

y = [0, 0, 0, 1, 1, 1] # Labels for supervised

Class labels

# 1. Supervised Learning (Uses both X and y):

KNN model

knn = KNeighborsClassifier(n_neighbors=1).fit(X, y)

Fit with labels

print("Supervised Prediction for [2,3]:", knn.predict([[2, 3]]))

Predict label

# 2. Unsupervised Learning (Uses ONLY X! No labels given!):

K-Means model

kmeans = KMeans(n_clusters=2, random_state=42).fit(X)

Find 2 natural clusters

print("Unsupervised Cluster Assignments:", kmeans.labels_)

Display discovered clusters

📋 Complete Script (All-in-One)

Click "Copy for Colab", open Google Colab, paste into a single cell, and run.

Google Colab Notebook Scriptpython
1# =========================================================
2# Comparing Supervised vs Unsupervised in Code
3# Prepared for Google Colab (Run with Shift + Enter)
4# =========================================================
5
6# Step 1: Install required packages
7!pip install scikit-learn numpy
8
9# Step 2: Import libraries
10from sklearn.neighbors import KNeighborsClassifier
11from sklearn.cluster import KMeans
12import numpy as np
13
14# Step 3: Run Demonstration
15X = np.array([[1, 2], [1, 4], [2, 2], [8, 7], [9, 8], [8, 9]])
16y = [0, 0, 0, 1, 1, 1] # Labels for supervised
17
18# 1. Supervised Learning (Uses both X and y):
19knn = KNeighborsClassifier(n_neighbors=1).fit(X, y)
20print("Supervised Prediction for [2,3]:", knn.predict([[2, 3]]))
21
22# 2. Unsupervised Learning (Uses ONLY X! No labels given!):
23kmeans = KMeans(n_clusters=2, random_state=42).fit(X)
24print("Unsupervised Cluster Assignments:", kmeans.labels_)
⚡ How to Run in Google Colab (3 Quick Steps)
  1. Click "Copy for Google Colab" above.
  2. Click Open New Google Colab Notebook (opens in a new tab).
  3. Click on the first empty code cell, press Ctrl + V (or Cmd + V) to paste, then press Shift + Enter to execute!

🔄 Algorithmic Execution Flow

1
Supervised Execution

KNN learns boundary separating class 0 from class 1.

→
2
Unsupervised Execution

K-Means groups the points into 2 geographic clusters purely by coordinate proximity.

📥 Input / Initial State
6 points with two distinct geometric clusters
📤 Expected Output
Supervised Prediction for [2,3]: [0]
Unsupervised Cluster Assignments: [1 1 1 0 0 0]
💡 What Does This Demonstration Show?

The unsupervised algorithm automatically discovered the two natural clusters without ever being told what the classes were!

Course Learning Resource • Slide DeckLesson 211 Slides

Lesson 2: Classical Machine Learning as the Starting Point

Data, prediction, and the bridge to modern artificial intelligence.

Author: Dr. Syed Muzamil Basha• FDP Approved Curriculum
Open in New Tab

📝 Learning Check

Test your understanding with these questions. Remember, this is for learning, not examination!

Question 1: Which machine learning paradigm operates entirely without ground-truth labels?

Question 2: AlphaGo mastered the game of Go by playing millions of games against itself and receiving win/loss feedback. Which ML paradigm best describes this?

Question 3: A bank wants to group 2 million customers by spending behavior without any prior category definitions. Which ML paradigm should they use?

Question 4: Which statement correctly differentiates supervised and reinforcement learning?

Question 5: A self-driving car system is trained on 1 million dashcam images labeled "pedestrian", "vehicle", or "traffic light". A separate module groups GPS trajectories into natural route clusters without labels. Which paradigms are used respectively?

Question 6: What is the primary challenge that makes obtaining labeled data expensive in supervised learning?