Curriculum01. Machine Learning FundamentalsLesson 2 of 6

Types of Machine Learning

Comparing supervised, unsupervised, semi-supervised, and reinforcement paradigms.

14 min readBeginnerModule 01
01 // CORE INTUITION

Core Intuition: Four Ways a Learner Receives Feedback

Think about how four different students prepare for an unfamiliar subject. One studies flashcards with exact answers printed on the back (Supervised). Another sorts a box of unlabelled mineral samples by weight and luster (Unsupervised).

A third checks a few labeled samples from an instructor, then groups hundreds of unlabeled rocks by similarity (Semi-Supervised). A fourth learns to ride a bicycle by steering, wobbling, and adjusting balance from immediate physical feedback (Reinforcement).

Takeaway:The feedback signal available in your data dictates which Machine Learning paradigm applies.
02 // THE PROBLEM IT SOLVES

The Problem It Solves: Matching Data Reality to Algorithms

Real-world datasets rarely arrive neatly packaged with clean target columns. Medical image archives often contain 100,000 raw scans and only 500 radiologist diagnoses. Robotics simulations generate action trajectories without pre-labeled "optimal move" answers.

Forcing every problem into a single paradigm wastes available signals or stalls when labels are missing. Choosing the right learning family matches the algorithm directly to the feedback your environment actually supplies.

Takeaway:Audit whether your problem provides full labels, partial labels, zero labels, or sequential rewards before selecting a model.
03 // STEP-BY-STEP MECHANISM

Step-by-Step Mechanism: Feedback Loops Across Paradigms

Each paradigm executes a distinct update cycle based on its feedback structure:

1. Supervised: Receive pairs (x(i),y(i))(\mathbf{x}^{(i)}, y^{(i)}), predict y^(i)\hat{y}^{(i)}, and minimize prediction loss L(y(i),y^(i))L(y^{(i)}, \hat{y}^{(i)}).

2. Unsupervised: Receive raw vectors x(i)\mathbf{x}^{(i)} only, and optimize structural objectives like cluster compactness or reconstruction error.

3. Semi-Supervised: Train on a small labeled subset, assign confident pseudo-labels or smooth manifold constraints across abundant unlabeled points, and iterate.

4. Reinforcement: Observe state sts_t, execute action ata_t, collect scalar reward rtr_t, and update policy π(at∣st)\pi(a_t \mid s_t) to maximize cumulative future return.

Takeaway:Supervised and unsupervised models learn from static datasets; reinforcement agents shape their own future data through actions.
04 // INTERACTIVE SANDBOX

Interactive Sandbox: Paradigm Signal Explorer

Switch between the four learning paradigms to inspect how data inputs, feedback signals, and parameter updates differ on the same visual canvas.

Observe how Supervised updates pull toward target labels, Unsupervised shifts prototypes toward unlabeled density centers, Semi-Supervised propagates labels across neighbors, and Reinforcement updates action probabilities from delayed rewards.

Learning Paradigm Signal Visualizer
InputPairs (x^(i), y^(i))
FeedbackExact target label y^(i)
Objectivemin L(y, f(x))

Every training sample carries an explicit ground-truth label guiding the dividing boundary.

Feature x₁Feature x₂
Takeaway:Every paradigm transforms its available feedback signal into a distinct geometric update rule.
05 // MATHEMATICAL FORMULATION

Mathematical Formulation: Four Objective Functions

Mathematically, semi-supervised learning bridges supervised and unsupervised objectives by adding a consistency term weighted by λ\lambda over unlabeled points U\mathcal{U}. Reinforcement learning swaps static dataset sums for expected discounted return E[∑t=0∞γtrt]\mathbb{E}[\sum_{t=0}^{\infty} \gamma^t r_t] over sequential trajectories.

PRIMARY OBJECTIVE FORMULATION
Variable & Symbol Definitions
L(y(i),f(x(i)))L(y^{(i)}, f(\mathbf{x}^{(i)}))Supervised loss computed on labeled pairs (x(i),y(i))(\mathbf{x}^{(i)}, y^{(i)})
L,U\mathcal{L}, \mathcal{U}Index sets of labeled observations and unlabeled observations
R(x(j))R(\mathbf{x}^{(j)})Unsupervised consistency or cluster regularization term over unlabeled sample x(j)\mathbf{x}^{(j)}
λ\lambdaWeight balancing labeled supervision against unlabeled geometric structure
Takeaway:Semi-supervised objectives combine labeled loss with an unsupervised geometric regularizer controlled by λ\lambda.
06 // KEY ASSUMPTIONS

Key Assumptions: Smoothness, Clusters & Markov States

Each paradigm relies on structural assumptions about the world:

1. Supervised Assumption: Labels yiy_i accurately measure the target concept with manageable label noise.

2. Semi-Supervised Smoothness: Nearby points in high-density regions share the same label; decision boundaries pass through low-density gaps.

3. Reinforcement Markov Property: The current state sts_t summarizes all past history needed to choose optimal action ata_t and predict reward rtr_t.

Takeaway:Semi-supervised learning fails if nearby points cross class boundaries; reinforcement learning degrades if states omit key history.
07 // COMMON PITFALLS

Common Pitfalls: Confirmation Bias & Reward Hacking

In semi-supervised self-training, early confident mistakes get reinforced as permanent pseudo-labels, creating runaway confirmation bias. Setting too low a confidence threshold contaminates the training pool.

In reinforcement learning, poorly designed rewards trigger reward hacking: an agent maximizes the proxy score rtr_t without solving the intended task (for example, spinning in circles to collect checkpoint points).

Algorithmic Checkpoint

You have 200 labeled customer support tickets and 50,000 unlabeled tickets, plus no reward loop. Which paradigm fits best?

Takeaway:Guard against pseudo-label drift in semi-supervised pipelines and inspect reward incentives closely in RL.
08 // COMPLEXITY

Computational Complexity: Annotation vs. Sample Efficiency

Supervised learning offers high sample efficiency (O(m⋅d)O(m \cdot d) training per pass) but requires O(m)O(m) human annotation cost. Unsupervised learning removes labeling cost entirely, though structure discovery like pairwise similarity scales O(m2)O(m^2) unless approximated.

Reinforcement learning typically exhibits the highest sample complexity, often requiring millions of simulated environment rollouts (O(E⋅T)O(E \cdot T) for EE episodes of length TT) because each trajectory reveals only sparse scalar rewards.

Takeaway:Human labeling cost is lowest in unsupervised learning, while simulation compute cost is highest in reinforcement learning.
09 // REAL-WORLD USE

Real-World Use: Modern Self-Supervised Pretraining

Large language and vision systems blend these paradigms in stages. First, self-supervised pretraining (an unsupervised variant that creates masked-word targets directly from raw text) learns rich representations across billions of unlabeled documents.

Next, supervised fine-tuning adapts the model to curated question-answer pairs. Finally, reinforcement learning aligns outputs using human preference rewards.

Takeaway:Modern production models stack unsupervised pretraining, supervised fine-tuning, and reinforcement alignment.
10 // PRODUCTION CODE

Production Code: Semi-Supervised Label Propagation

Compare a NumPy nearest-neighbor pseudo-label step with scikit-learn SelfTrainingClassifier on partially labeled observations.

Production Implementation
import numpy as np

# 2 labeled points and 4 unlabeled points (-1 marks unlabeled)
X = np.array([[0.0, 0.1], [0.2, 0.0], [0.1, 0.2], [5.0, 5.1], [5.2, 4.9], [4.9, 5.0]])
y = np.array([0, -1, -1, 1, -1, -1])

labeled_mask = y != -1
X_labeled, y_labeled = X[labeled_mask], y[labeled_mask]
X_unlabeled = X[~labeled_mask]

# Propagate label from closest labeled sample in Euclidean space
dists = np.linalg.norm(X_unlabeled[:, None, :] - X_labeled[None, :, :], axis=2)
pseudo_labels = y_labeled[np.argmin(dists, axis=1)]

y_filled = y.copy()
y_filled[~labeled_mask] = pseudo_labels
print("Propagated labels:", y_filled)
Implementation Walkthrough:

In the NumPy implementation, broadcasting computes pairwise distances from every unlabeled point to the labeled anchors and propagates labels across local neighborhoods. In scikit-learn, SelfTrainingClassifier wraps any probabilistic base estimator, iteratively adding unlabeled points whose predicted probability exceeds threshold=0.75.

Takeaway:Use confidence thresholding (threshold >= 0.75) when pseudo-labeling unlabeled points to prevent error amplification.