Computer Engineering is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

Deep learning vs machine learning

Clear, exam-focused notes comparing deep learning and traditional machine learning: definitions, exact statements (including the universal approximation theorem and empirical risk minimisation), formulas, worked model-answer examples, common mistakes and quick revision questions.

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

Deep learning and machine learning are both ways engineers build systems that make predictions from data. Knowing when to use a deep neural network versus a classical machine-learning method (for example, a support-vector machine or random forest) helps you choose an approach that fits the data size, compute budget, need for interpretability and time available for feature engineering.

Key ideas

Start from first principles and definitions.

  • Data (training set): a finite set of examples (x_i, y_i) where x is an input (vector, image, sequence) and y is the target (label, real value). We call the true but unknown distribution P(x,y) the data distribution.

  • Model: a parameterised mapping f(x; θ) from input to output. The parameters θ are real numbers learned from data.

  • Machine learning (ML): methods that build a model f by optimising a loss on training data; often rely on hand-designed features. Definition: ML = algorithms that map inputs to outputs using learned parameters and may require explicit feature engineering.

  • Deep learning (DL): a subset of ML where the model f is a deep neural network, meaning it has multiple layers of parameterised linear transforms and nonlinearities so it learns hierarchical representations from raw inputs. Definition: DL = ML using neural networks with many (usually >1) learned layers that perform representation learning.

  • Representation learning: automatic learning of features or representations of input data that make downstream tasks (classification, regression) easier. Deep networks perform representation learning across layers.

  • Empirical risk minimisation (ERM): choose θ to minimise average loss on training set: precise statement—given loss ℓ(y, f(x; θ)), ERM selects θ̂ = argmin_θ (1/n) Σ_{i=1}^n ℓ(y_i, f(x_i; θ)). Assumes samples are i.i.d. from P(x,y).

  • Capacity: the set of functions a model class can represent. High-capacity models can fit complex functions; low-capacity models are simpler.

  • Overfitting and generalisation: Overfitting = model fits training data well but fails on new data. Generalisation = performance on new data. Regularisation, validation sets and early stopping are ways to control overfitting.

Exact statement used often in exams:

  • Universal approximation theorem (informal exact statement): A feed-forward neural network with a single hidden layer and a non-polynomial continuous activation (e.g., sigmoid) can approximate any continuous function on a compact subset of R^d to any desired tolerance, provided the hidden layer has sufficiently many units. Assumptions: activation is non-polynomial and continuous; domain is compact; approximation in uniform norm. Note this theorem does not say how many units are needed, nor anything about training/convergence.

Derivations/explanations commonly asked:

  1. From ERM to gradient descent update (describe steps):

    • Write empirical risk R(θ) = (1/n) Σ ℓ(y_i, f(x_i; θ)).
    • Compute gradient ∇_θ R(θ) = (1/n) Σ ∇_θ ℓ(y_i, f(x_i; θ)).
    • Gradient descent update: θ_{t+1} = θ_t − η ∇_θ R(θ_t), with learning rate η > 0.
    • For stochastic gradient descent (SGD), use a minibatch estimate of the gradient.
  2. Why depth can help (sketch of argument often expected in exams):

    • Certain functions are compositional (f(x) = f_k(...f_2(f_1(x))...)). A deep network can represent such compositional functions with many fewer parameters than a shallow network that must expand composition into a large equivalent shallow basis. Provide a short counting argument: a composition of like-sized maps can produce exponentially many distinct linear regions with affine (linear) layers between nonlinearities (e.g., ReLU), so depth increases representational efficiency.

Diagrams to draw (describe exactly):

  • Diagram 1: “Classical ML pipeline” — draw boxes left-to-right: Data → Manual feature engineering (box) → Shallow model (SVM/logistic/regression) → Output. Label arrow from Data to Feature engineering as “requires domain knowledge”.

  • Diagram 2: “Deep learning pipeline” — draw boxes: Data → Deep neural network (many stacked layers) → Output. Label inside Deep net: Layer 1 (low-level features), Layer 2 (higher-level), …, Layer L (task output). Add note “end-to-end learning; fewer hand features”.

  • Diagram 3: Simple graph comparing capacity vs data: x-axis Data size, y-axis preferred model: small data → classical ML (low variance), large data/compute → deep learning (high capacity). Mark interpretability trade-off.

Formulas

θ̂ = argmin_θ (1/n) Σ_{i=1}^n ℓ(y_i, f(x_i; θ)) — θ̂: learned parameters (units depend on model/feature scaling; often treated as dimensionless after normalisation), n: number of training examples (dimensionless), ℓ: loss function (units depend on loss; often dimensionless). Applies: empirical risk minimisation under i.i.d. assumption.

R(θ) = (1/n) Σ_{i=1}^n ℓ(y_i, f(x_i; θ)) — R(θ): empirical risk (loss units), symbols as above. Applies when using average loss as objective.

θ_{t+1} = θ_t − η ∇_θ R(θ_t) — η: learning rate (units chosen so that η ∇_θ R has the same units as θ; often treated as dimensionless after normalisation), ∇_θ R: gradient (units of loss per unit of θ), applies for gradient descent updates.

θ_{t+1} = θ_t − η (1/m) Σ_{j∈B} ∇_θ ℓ(y_j, f(x_j; θ_t)) — minibatch SGD update; m: minibatch size (dimensionless), B: minibatch indices.

#params ≈ Σ_{l=1}^L (n_{l−1} · n_l + n_l) — approximate count of parameters in fully connected network: n_l units in layer l, n_{l−1} units previous layer, bias per unit (dimensionless). Applies to dense layers.

Empirical generalisation bound (high-level) : Test error ≤ Train error + O(√(capacity/n)) — capacity: measure of model complexity (VC dimension or Rademacher complexity), n: number of examples. Units: error (same as loss). Applies as loose intuition; constants depend on bound used.

Worked examples

Note: exam-style model answers (theory questions).

Example 1 — Short essay: "Compare deep learning and classical machine learning, and give when to prefer each." Model answer (exam standard):

  1. Definition: Give definitions of ML and DL (as above).
  2. Differences in pipeline: Draw or describe pipelines (manual features vs representation learning).
  3. Data and compute: DL needs large labelled datasets and more compute (GPUs); ML methods can work better with small datasets.
  4. Feature engineering vs end-to-end: ML often requires domain features; DL learns hierarchical features automatically.
  5. Interpretability and debugging: classical models (linear models, decision trees) are more interpretable; DL models are opaque though explainability research exists.
  6. When to use: Use DL for image, speech, NLP, and cases with large data and complex structure. Use classical ML for small datasets, tabular data with strong domain features, or when interpretability and fast training are priorities.

Final sentence to score full marks: Conclude with concise rule-of-thumb: "Large data + compute + inputs like images, audio, or text → prefer deep learning; small data, tabular data, strict interpretability or low compute → prefer classical ML."

Example 2 — Derivation-style question: "Show how gradient descent update arises from minimising empirical squared loss for linear regression." Model answer with steps:

  1. Problem: given data (x_i, y_i), linear model f(x; w) = w^T x where w ∈ R^d.
  2. Loss: ℓ_i(w) = (1/2)(y_i − w^T x_i)^2; empirical risk R(w) = (1/n) Σ ℓ_i(w).
  3. Compute gradient: ∇_w R(w) = (1/n) Σ (−x_i (y_i − w^T x_i)).
  4. Gradient descent update: w_{t+1} = w_t − η ∇_w R(w_t) = w_t + η (1/n) Σ x_i (y_i − w_t^T x_i).
  5. Interpret: each step moves w in direction that reduces residuals; factor 1/2 in loss cancels the 2 from derivative. Mention conditions on η for convergence (0 < η < 2/λ_max((1/n) X^T X) in the quadratic case), where λ_max is the largest eigenvalue of the Hessian H = (1/n) X^T X (often called the Gram matrix). (State this requirement; mark as an item to verify for your course.)

Conclude with final boxed update (for exam style): w_{t+1} = w_t + (η/n) Σ x_i (y_i − w_t^T x_i).

Common mistakes

  • Saying deep learning always outperforms classical ML: counterexamples include small-tabular datasets and low-sample regimes where simpler models win.
  • Forgetting to state i.i.d. assumption when invoking ERM or generalisation bounds.
  • Omitting units or failing to state dimension assumptions (e.g., after normalisation) for parameters and the learning rate in formulae.
  • Mixing up validation and test sets: validation for tuning, test only for final evaluation.

For your exam

Question types you will see on this topic:

  • Definitions and short notes (define ML, DL, representation learning, ERM, universal approximation theorem). Full marks require precise definitions and assumptions.
  • Derivations (derive gradient descent update from ERM; show gradient for logistic loss). Full marks: show steps, derivatives, and state assumptions (differentiability, convexity if used).
  • Comparative essays/diagrams (draw the ML vs DL pipelines, discuss pros/cons). Full marks: include diagrams as described, list trade-offs and a clear conclusion.
  • Numerical or pseudo-numeric: parameter count, compute FLOPs for a small network. Full marks: show arithmetic, units and final number.

Quick check

  1. Define deep learning in one sentence.
  2. State the empirical risk minimisation objective for n examples.
  3. Give one reason why a deep network may generalise poorly despite low training error.

Answers: 1) Deep learning is machine learning using neural networks with multiple learned layers that perform representation learning. 2) θ̂ = argmin_θ (1/n) Σ_{i=1}^n ℓ(y_i, f(x_i; θ)). 3) Overfitting due to excessive capacity relative to dataset size (insufficient regularisation).

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?