Types of learning
Overview of the main types of machine learning (supervised, unsupervised, semi‑supervised, reinforcement, self‑supervised, transfer, online/batch, active and federated), with formal definitions, core formulas (empirical/expected risk), exam-style derivations, diagrams to draw, worked model-answer ex
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Engineers use different types of learning when designing systems that must make predictions, find structure in data, learn from scarce labels, or act in an environment. Choosing the correct type of learning determines the right algorithms, data collection strategy, evaluation metrics and deployment design (for example: supervised models for classification, unsupervised for clustering, reinforcement learning for control, and federated learning when data cannot leave devices).
Key ideas
Start from first principles. I state and define each main type clearly, give the assumptions behind each, and show the simple derivations and diagrams exam answers usually need.
Definition: Supervised learning — a learning setup where the training data are pairs (x, y) with inputs x and target outputs y, drawn i.i.d. from an unknown joint distribution P(x,y). The aim is to learn a function f: X → Y such that f(x) approximates y for new samples. Assumption: labelled examples are available and representative of test distribution.
Definition: Unsupervised learning — a learning setup where training data consist only of inputs x (no target y). The aim is to discover structure in the distribution of x (clusters, density, low‑dimensional manifold). Assumption: no labels; structure can be discovered from input distribution alone.
Definition: Semi‑supervised learning — uses a mixture of a small labelled set and a larger unlabelled set to improve learning. Assumptions used by methods: (a) cluster assumption — points in same cluster share label; (b) low‑density separation — decision boundary lies in low‑density regions; (c) manifold assumption — data lie on low‑dimensional manifold.
Definition: Reinforcement learning (RL) — an agent interacts with an environment in discrete time: at time t it observes state s_t, selects action a_t, receives reward r_{t+1} and transitions to s_{t+1}. The objective is to learn a policy π(a|s) that maximises expected cumulative reward. Assumption: interactions and feedback are available; model may be stochastic. Typically modeled as a Markov decision process (MDP) satisfying the Markov property.
Definition: Self‑supervised learning — a family of methods that create supervised tasks from unlabeled data by deriving pseudo‑labels from data itself (for example: predicting a missing part of input). Assumption: a pretext task correlates with downstream labels so representations learned transfer.
Definition: Transfer learning — reusing a model (or representation) trained on one task/domain to help learning in another (target) task/domain. Assumption: source and target are related so knowledge transfers.
Definition: Online learning — data arrive as a stream and the model updates incrementally per observation (or small batches). Assumption: possibly non‑stationary data; memory or compute requires incremental updates. Typical evaluation uses regret (cumulative loss relative to the best fixed comparator).
Definition: Batch (offline) learning — model is trained on a fixed dataset available in full; updates usually re‑train on the whole dataset or large mini‑batches.
Definition: Active learning — the learner may query an oracle (human annotator) for labels of selected unlabeled examples to maximize performance with fewer labels. Assumption: labelling cost is high; oracle is available and accurate.
Definition: Federated learning — distributed training where data remain on client devices and only model updates (gradients/weights) are aggregated centrally to learn a global model. Assumption: privacy or bandwidth constraints prevent centralising raw data.
Important formalism (used by supervised and semi‑supervised theory):
Definition: Expected risk (true risk) of a predictor f under loss L is the expectation under P(x,y): R(f) = E_{(x,y)~P}[L(f(x), y)]. Assumption: P is fixed but unknown.
Definition: Empirical risk on dataset D = {(x_i,y_i)}{i=1}^n is the sample average: R_n(f) = (1/n) Σ{i=1}^n L(f(x_i), y_i).
Principle: Empirical Risk Minimisation (ERM) — select f̂ ∈ H that minimises R_n(f) over hypothesis class H. Assumption: H contains good predictors and n is sufficient for generalisation.
Derivations commonly asked in exams (simple):
Show the empirical risk is an unbiased estimator of expected risk for fixed f (same f independent of training sample): E_D[R_n(f)] = R(f). Steps: write expectation over data, move expectation inside sum because of linearity, each term equals E[L(f(x_i),y_i)] = R(f).
For finite hypothesis class H, a basic uniform convergence bound (use Hoeffding + union bound) commonly appears in exam outlines: with probability ≥ 1−δ, for all f ∈ H, R(f) ≤ R_n(f) + sqrt((ln(2|H|/δ))/(2n)). Assumptions: losses bounded in [0,1]; samples i.i.d.; finite |H|. (State these assumptions explicitly.)
Diagrams to draw (describe exactly):
Supervised vs unsupervised: Draw a 2D scatter plot of points (x1,x2). For supervised: colour points by label (red/blue) and draw a decision boundary line separating colors; label axes x1,x2 and legend for classes. For unsupervised: draw same points without colours, then draw cluster boundaries (ellipses) grouping points; label as clusters found by algorithm.
Semi‑supervised: draw many points, mark a few with labels (solid colour) and many unlabeled (grey). Draw clusters where labelled points suggest labels extend to nearby unlabeled points.
Federated learning: draw several client devices each with local data box, arrows showing local training and sending model updates (not raw data) to central server which aggregates and sends global model back.
Formulas
R(f) = E_{(x,y)~P}[L(f(x),y)] — R(f): expected (true) risk; L: loss function (unit depends on choice; often unitless if 0–1-loss); applies when P is probability distribution over X×Y.
R_n(f) = (1/n) Σ_{i=1}^n L(f(x_i), y_i) — R_n(f): empirical risk on n labelled samples; units same as L; applies for i.i.d. sample D.
f̂_ERM = argmin_{f∈H} R_n(f) — ERM estimator: choose f in hypothesis class H minimising empirical risk; assumes H is specified.
With prob ≥ 1−δ: ∀ f∈H, R(f) ≤ R_n(f) + sqrt((ln(2|H|/δ))/(2n)) — uniform convergence bound for finite H; assumptions: losses in [0,1], i.i.d. data.
G_t = Σ_{k=0}^∞ γ^k r_{t+k+1} — return in reinforcement learning; G_t: cumulative discounted reward at time t; γ ∈ [0,1): discount factor (unit: reward units); applies in infinite horizon discounted RL.
Worked examples
Example 1 — Model answer (theory): Compare supervised and unsupervised learning, give algorithms and when to use each. (Exam-style long question)
Answer: (Structure: definition, data, main algorithms, use cases, evaluation)
- Definitions: Supervised learning uses labelled pairs (x,y); unsupervised learning uses only x. (Write the formal definitions above in one line each.)
- Main algorithms: Supervised — logistic regression, linear regression, SVM, decision trees, random forest, neural networks. Unsupervised — k‑means, hierarchical clustering, Gaussian mixture models, PCA, DBSCAN. Cite assumptions (e.g., k‑means assumes spherical clusters of similar size; GMM assumes mixture of Gaussians).
- Evaluation: Supervised — accuracy, precision/recall, cross‑validation. Unsupervised — intrinsic metrics (silhouette), extrinsic if labels are available, visual inspection and downstream task performance.
- When to use: If labelled data are available and the task is prediction, use supervised. If labels are not available and you need grouping, compression or anomaly detection, use unsupervised. Semi‑supervised sits between: useful when a small labelled set and many unlabeled samples exist.
Conclude by giving a diagram: sketch a 2D scatter with labels and decision boundary (for supervised) and clusters (for unsupervised). Mark assumptions under each algorithm.
Example 2 — Applied design (semi‑supervised + transfer): You have 10,000 images of mechanical parts; only 500 are labelled defective/non‑defective. Which learning strategy and why? Provide a stepwise plan.
Answer:
- Problem: binary classification with many unlabeled images and few labels. Best choices: (a) transfer learning (pretrained CNN) + fine‑tune; (b) self‑supervised pretraining on the 10,000 unlabeled images followed by supervised fine‑tune on 500 labels; (c) semi‑supervised learning (consistency regularisation or pseudo‑labeling) possibly combined with active learning to label most informative images.
- Concrete plan (steps): a. Pretrain a convolutional network using a self‑supervised task (for example, contrastive learning) on all 10,000 images. Reason: learn representations without labels. b. Initialise classifier head and fine‑tune on the 500 labelled samples (use data augmentation). Use cross‑validation to estimate performance. c. Use active learning: select top 200 most uncertain or representative unlabeled images (uncertainty from classifier, e.g., margin or entropy) and obtain labels from an expert; re‑train or fine‑tune. d. Optionally apply pseudo‑labeling: assign labels to high‑confidence unlabeled examples and retrain iteratively.
- Metrics: Use precision/recall (defects are usually rare) and confusion matrix; report results with cross‑validation.
Example 3 — Short derivation exam question: Show that empirical risk is an unbiased estimator of expected risk for fixed f.
Answer (stepwise):
- Definition: R_n(f) = (1/n) Σ_{i=1}^n L(f(x_i), y_i).
- Take expectation over dataset D of size n: E_D[R_n(f)] = (1/n) Σ_{i=1}^n E_{(x_i,y_i)}[L(f(x_i),y_i)].
- Since each sample is drawn i.i.d. from P, each expectation equals R(f). So sum gives (1/n)·n·R(f) = R(f). Therefore E_D[R_n(f)] = R(f). QED.
Final answers: Make the difference between the estimator being unbiased for fixed f and not necessarily for f̂ chosen by ERM (because f̂ depends on data). State this caveat explicitly.
Common mistakes
- Confusing semi‑supervised with weak supervision; they are different (semi‑supervised uses unlabeled examples, weak supervision uses noisy/cheap labels).
- Treating empirical risk of f̂ as unbiased for expected risk (the unbiasedness proof applies to a fixed f chosen before seeing data; f̂ depends on data so bias may exist).
- In RL, treating rewards as immediate labels like supervised learning — RL has delayed rewards and sequential dependence; do not assume i.i.d.
- In federated learning, thinking only model weights are private — gradients can leak data; mention privacy mechanisms if asked.
For your exam
Question types that appear: definitions (short), compare and contrast (short note), derivations (show unbiasedness, derive simple bounds), design questions (choose learning type and justify), diagrams (draw data with clusters and decision boundaries), and brief algorithm outlines (how to do semi‑supervised, active learning loop, or federated averaging).
What a full‑marks answer includes:
- Precise definitions with bold terms (supervised / unsupervised / semi‑supervised / RL / self‑supervised / transfer / online / batch / active / federated).
- Clear statement of assumptions for each method/ bound used.
- Exact formulas where needed (empirical/expected risk, ERM choice) and short derivations with steps.
- Diagrams labelled correctly when asked.
- For design questions: list steps, justify choices, discuss evaluation metrics and limitations.
Quick check
- What is the difference between empirical risk and expected risk?
- Name two assumptions used by semi‑supervised learning methods.
- In federated learning, what is sent from clients to server instead of raw data?
Answers: Empirical risk is the sample average loss on labelled training data, expected risk is the true population expectation of loss under P(x,y); assumptions: cluster assumption and manifold assumption (also low‑density separation); clients send model updates (gradients or weight updates), not raw data.
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?