The Math You Need, and Where to Learn It
Machine learning stands on three branches of mathematics: linear algebra to represent data and models, calculus and optimisation to train them, and probability and statistics to reason about uncertainty and to evaluate them honestly. You do not need to master all of it before you start; you need to know what each part is for, so you can learn it when a lesson calls for it. This page is that map. Every topic links to the lessons on this site that teach it.
The three branches in one example
The example touches all three: a layer of a model is a matrix product (linear algebra), its training signal is a derivative (calculus), and its output is turned into probabilities (probability).
import numpy as np
# Linear algebra: a batch of inputs times a weight matrix is one layer of a model.
X = np.array([[1.0, 2.0, 0.5],
[0.0, 1.0, 3.0]]) # 2 examples, 3 features
W = np.array([[0.2, -0.1],
[0.4, 0.3],
[-0.5, 0.1]]) # 3 inputs -> 2 outputs
b = np.array([0.1, -0.2])
Z = X @ W + b
print("layer output Z =\n", Z.round(3))
# Calculus: the gradient says how the loss changes when a weight changes.
x, y = 2.0, 7.0
loss = lambda w: (w * x - y) ** 2
w, h = 3.0, 1e-6
numeric = (loss(w + h) - loss(w - h)) / (2 * h)
analytic = 2 * (w * x - y) * x # chain rule
print("dL/dw numeric", round(numeric, 4), " analytic", analytic)
# Probability: softmax turns raw scores into a probability distribution.
scores = Z[0]
p = np.exp(scores - scores.max()) / np.exp(scores - scores.max()).sum()
print("softmax probabilities", p.round(3), " sum", p.sum().round(3))layer output Z =
[[ 0.85 0.35]
[-1. 0.4 ]]
dL/dw numeric -4.0 analytic -4.0
softmax probabilities [0.622 0.378] sum 1.0
- Linear algebra. computes both examples' outputs at once: a matrix times a matrix gives . For the first example, .
- Calculus. For the chain rule gives . The negative sign says: increase to lower the loss. The numerical estimate agrees, a check called gradient checking.
- Probability. The softmax turns the scores 0.85 and 0.35 into probabilities 0.622 and 0.378 that sum to 1.
Linear algebra (curriculum module 3)
Data sets are matrices (rows = examples, columns = features), model weights are matrices, and a neural network is mostly matrix multiplication.
| Topic | Why ML needs it | Learn it in |
|---|---|---|
| Scalars, vectors and matrices | every example is a vector, every data set a matrix | Vectors, Matrices, Data as Matrices |
| Tensors and shapes | images and batches are 3-D and 4-D arrays; shape errors are the commonest bug | Tensors and Shapes, Einsum and Broadcasting |
| Matrix addition and subtraction | adding biases, combining feature matrices | Matrix Addition |
| Matrix multiplication | every layer, every linear model | Matrix Multiplication, Neural Network Layers |
| Dot products and norms | similarity, distances (kNN, k-means), regularisation | Dot Product, Vector Length, Norms, Embeddings and Similarity |
| Transpose and inverse | the least-squares solution, covariance matrices | Transpose, Matrix Inverses, Least Squares |
| Linear transformations | what a layer does geometrically | Linear Transformations, Linear Mappings |
| Eigenvalues and eigenvectors | PCA, stability of training, PageRank | Eigenvectors, Eigenvalues (math-ml), PCA |
| Singular value decomposition | compression, PCA, low-rank adapters (LoRA) | SVD, SVD for ML, Low-Rank Approximation |
| Practical linear algebra with NumPy | doing all of the above in code | Linear Algebra with Python, ML Math with NumPy |
Calculus and optimisation (curriculum module 4)
Training means minimising a loss, and that means derivatives.
| Topic | Why ML needs it | Learn it in |
|---|---|---|
| Functions and graphs | models and losses are functions; activations are functions | Functions, Exponential and Log Functions |
| Limits and continuity | the foundation of derivatives; why some losses are hard to optimise | Limits, Continuity |
| Derivatives | how the loss changes with one parameter | The Derivative, Derivatives and Taylor Series |
| Partial derivatives | models have many parameters | Partial Derivatives, Partial Derivatives and Gradients |
| Chain rule | backpropagation is the chain rule applied layer by layer | Chain Rule, Multivariable Chain Rule |
| Gradients | the direction of steepest increase of the loss | The Gradient, Jacobians |
| Gradient descent | the training algorithm of most models | Gradient Descent (math-ml), Gradient Descent (optimization), Step Size and Momentum |
| Local minima and saddle points | why training can get stuck or slow down | Extrema, Optimality Conditions, Convexity, Curvature and the Hessian |
| Numerical optimisation | SGD, Newton and quasi-Newton methods, choosing a solver | Stochastic Gradient Descent, Newton's Method, L-BFGS, Training ML Models |
| Automatic differentiation | how frameworks compute gradients for you | Automatic Differentiation, Backpropagation and Autodiff, A Tiny Autodiff |
Probability and statistics (curriculum module 5)
Data is noisy, predictions are uncertain, and every score is measured on a sample.
| Topic | Why ML needs it | Learn it in |
|---|---|---|
| Descriptive statistics | the first look at any data set | Descriptive Statistics, Describing Data |
| Mean, median and mode | centres of distributions; imputation choices | Mean, Median, Mode |
| Variance and standard deviation | spread; scaling features; noise | Standard Deviation, Variance |
| Probability and conditional probability | classifiers output probabilities; is what they model | Probability Rules, Conditional Probability |
| Random variables | features, labels and noise are random variables | Discrete and Continuous Variables, Expected Value |
| Probability distributions | modelling data and noise; generative models | Probability Distributions, Density Functions |
| Normal and Bernoulli distributions | Gaussian noise behind squared error; Bernoulli behind log-loss | Normal Distribution, Binomial Probabilities, The Gaussian |
| Bayes' theorem | naive Bayes, updating beliefs, base rates in rare-event problems | Bayes' Theorem, Sum and Product Rules, Bayes, Naive Bayes |
| Sampling and sampling bias | whether training data represents the real world | Sample and Population, Sample Types, Statistical Pitfalls |
| Correlation and covariance | feature relationships, PCA, leakage hunting | Correlation, Covariance and Correlation, Covariance and Independence |
| Confidence intervals | how precise a test score is | Estimation, Proportion Estimation |
| Hypothesis testing | is model B really better than model A? | Hypothesis Testing, Testing a Proportion |
The Maximum Likelihood lesson connects probability to the losses used in training: minimising squared error and minimising log-loss are both maximum-likelihood estimation under a noise model.
Statistics in action: how sure is a test score?
A test score is measured on a sample of examples, so it has an error bar. For an accuracy measured on examples, the standard error is , and an approximate 95 % confidence interval is standard errors.
import numpy as np
# Statistics: is model B really better than model A, or is it noise from a small test set?
rng = np.random.default_rng(0)
n = 200
correct_a = rng.random(n) < 0.80 # model A right on about 80 % of 200 test rows
correct_b = rng.random(n) < 0.83 # model B right on about 83 %
for name, c in [("A", correct_a), ("B", correct_b)]:
acc = c.mean()
se = np.sqrt(acc * (1 - acc) / n) # standard error of a proportion
print(f"model {name}: accuracy {acc:.3f}, 95% interval [{acc - 1.96 * se:.3f}, {acc + 1.96 * se:.3f}]")model A: accuracy 0.725, 95% interval [0.663, 0.787]
model B: accuracy 0.835, 95% interval [0.784, 0.886]
Model A's true accuracy is 0.80, yet on these 200 rows it measured 0.725: pure sampling luck. Each interval is about wide. With 200 test examples, differences of a few points between models are within the noise; you need larger test sets, or paired comparisons on the same examples, before declaring a winner.
How much math, and when
- To start (this course and the data courses): averages, variance, percentages, a straight line, reading a matrix shape.
- For classical algorithms: vectors, dot products and norms; derivatives and gradients; conditional probability and Bayes.
- For deep learning: matrix multiplication and shapes, the chain rule, gradient descent and its variants, softmax and cross-entropy.
- For research-level work: the full Mathematics for Machine Learning and Math for Deep Learning courses.
A good habit: when a lesson in this track uses a formula you do not know, open the linked lesson, run its example, then come back. Learning the math in context sticks better than learning it all up front.
Practice
- What is the shape of if holds 64 images of 784 pixels each and maps 784 inputs to 128 outputs?
Answer
is and is , so is : 128 outputs for each of the 64 images.
- For with and , at which is the derivative zero, and what is the loss there?
Answer
gives . The loss is .
- A model scores 0.90 accuracy on 100 test examples. Compute the approximate 95 % confidence interval.
Answer
Standard error . The interval is .
Test yourself
Which branch of mathematics underlies backpropagation?
- Probability
- Calculus (the chain rule)
- Graph theory
- Number theory
What is the shape of the product of a matrix and a matrix?
- It is undefined
What does the softmax function produce?
- A sorted list of scores
- Non-negative numbers that sum to 1, usable as probabilities
- The largest score only
- A gradient
Two models score 0.81 and 0.83 accuracy on 200 test examples. What is the most careful conclusion?
- The second model is clearly better
- The difference is within the sampling noise of a 200-example test set
- The first model is better
- Accuracy cannot be compared