Skip to content
Module 03 of 1250 min readBeginner

From OLS to neural networks

The geometric and statistical lineage that connects a regression you understand to a neural network you don't.

25%

Listen along

Read “From OLS to neural networks” aloud

Plays in your browser using on-device text-to-speech — nothing leaves the page.

Learning objectives

By the end of this module, you should be able to:

  • 01Derive a neural network from a stack of regressions plus a non-linear activation
  • 02Explain backpropagation in plain English — what it computes and why it works
  • 03Recognise gradient descent and its variants (SGD, Adam) as the universal training algorithm
  • 04Defend the use of a neural network with reference to its model class, not its hype

Start with OLS regression: ŷ = wx + b. The model is linear; it has two parameters; we find them by minimising the sum of squared residuals. Replace x with a vector and (w, b) with a matrix and a bias, and we have multivariate regression: ŷ = Wx + b.

Stack a few regressions and you have a neural network

Take that linear layer's output and run it through a non-linear function — say ReLU, which is f(x) = max(0, x). Then feed the result into another linear layer. Then another. That stack is a neural network. The non-linear function between layers is what makes the whole thing capable of representing complex relationships.

python
import torch.nn as nn
net = nn.Sequential(
nn.Linear(in_features=10, out_features=64),
nn.ReLU(),
nn.Linear(64, 32),
nn.ReLU(),
nn.Linear(32, 1)
)

The loss function and gradient descent

Same as OLS: define a loss (mean squared error for regression, cross-entropy for classification), then find the weights that minimise it. The difference: with millions or billions of weights, you can't solve for the minimum analytically. You move iteratively.

Gradient descent: compute the gradient of the loss with respect to each weight, then nudge each weight in the direction that reduces loss. Repeat. Stochastic gradient descent does this on small random batches of data rather than the full dataset, which is faster and helps the model generalise.

Backpropagation

Computing the gradient through a deep network looks intractable but isn't. Backpropagation is just the chain rule applied systematically: the gradient at any layer is the gradient at the next layer times the local derivative. Modern frameworks (PyTorch, TensorFlow, JAX) compute this automatically.

The honest statement

A neural network is regression generalised — stacked linear layers with non-linearities between them, trained by gradient descent on a loss function. Everything else is engineering: choice of architecture, activation, optimiser, regularisation. The bones are familiar.

Why this scales

Stack more layers, widen them, train on more data — that's the story of deep learning from 2012 to 2024. The transformer architecture is one specific stack of layers (attention + feedforward + normalisation) that turned out to scale particularly well.

Exercise

A junior colleague claims 'neural networks are fundamentally different from linear regression — they have nothing in common.' In two paragraphs, respond. Explain what is true about the claim (where neural networks really do go beyond linear regression) and what is false (the structural continuity that the module emphasises). Make sure you cover the role of non-linear activation functions in your answer.

Key takeaways

  • A neural network is a stack of (Wx + b) operations with non-linear activations between them — essentially layered regressions
  • Backpropagation is the chain rule applied to compute the gradient of the loss with respect to each weight
  • Training = repeatedly nudging the weights down the loss gradient until the loss stops falling on a held-out set
  • Adam is the default optimiser in 2026; SGD with momentum is the rigorous-paper alternative

Further reading

  1. 01

    Deep Learning, Chapter 6: Deep Feedforward Networks

    Goodfellow, Bengio & Courville · MIT Press · 2016

  2. 02
  3. 03

    Adam: A Method for Stochastic Optimization

    Diederik P. Kingma & Jimmy Ba · ICLR · 2015

Loading progress…
LeadAfrikPublic Economics Hub