TExcelTAD
Home › ML Foundations: AI, ML, Deep Learning & the ML Lifecycle › The Math You Need, and Where to Learn It

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).

python · try it yourself
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. Z=XW+bZ = XW + \mathbf{b} computes both examples' outputs at once: a 2×32 \times 3 matrix times a 3×23 \times 2 matrix gives 2×22 \times 2. For the first example, 1⋅0.2+2⋅0.4+0.5⋅(−0.5)+0.1=0.851 \cdot 0.2 + 2 \cdot 0.4 + 0.5 \cdot (-0.5) + 0.1 = 0.85.
  • Calculus. For L(w)=(wx−y)2L(w) = (wx - y)^2 the chain rule gives dLdw=2(wx−y) x=2⋅(6−7)⋅2=−4\frac{dL}{dw} = 2(wx - y)\,x = 2 \cdot (6 - 7) \cdot 2 = -4. The negative sign says: increase ww to lower the loss. The numerical estimate agrees, a check called gradient checking.
  • Probability. The softmax pk=ezk∑jezjp_k = \frac{e^{z_k}}{\sum_j e^{z_j}} 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; P(y∣x)P(y \mid x) 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 p^\hat{p} measured on nn examples, the standard error is p^(1−p^)/n\sqrt{\hat{p}(1 - \hat{p})/n}, and an approximate 95 % confidence interval is p^±1.96\hat{p} \pm 1.96 standard errors.

python · try it yourself
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 ±0.06\pm 0.06 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

  1. What is the shape of XWXW if XX holds 64 images of 784 pixels each and WW maps 784 inputs to 128 outputs?
Answer

XX is 64×78464 \times 784 and WW is 784×128784 \times 128, so XWXW is 64×12864 \times 128: 128 outputs for each of the 64 images.

  1. For L(w)=(wx−y)2L(w) = (wx - y)^2 with x=2x = 2 and y=7y = 7, at which ww is the derivative zero, and what is the loss there?
Answer

dLdw=2(2w−7)⋅2=0\frac{dL}{dw} = 2(2w - 7) \cdot 2 = 0 gives w=3.5w = 3.5. The loss is (7−7)2=0(7 - 7)^2 = 0.

  1. A model scores 0.90 accuracy on 100 test examples. Compute the approximate 95 % confidence interval.
Answer

Standard error 0.9⋅0.1/100=0.03\sqrt{0.9 \cdot 0.1 / 100} = 0.03. The interval is 0.90±1.96⋅0.03≈[0.841,0.959]0.90 \pm 1.96 \cdot 0.03 \approx [0.841, 0.959].

Test yourself

Which branch of mathematics underlies backpropagation?

  1. Probability
  2. Calculus (the chain rule)
  3. Graph theory
  4. Number theory

What is the shape of the product of a 5×35 \times 3 matrix and a 3×43 \times 4 matrix?

  1. 3×33 \times 3
  2. 5×45 \times 4
  3. 4×54 \times 5
  4. It is undefined

What does the softmax function produce?

  1. A sorted list of scores
  2. Non-negative numbers that sum to 1, usable as probabilities
  3. The largest score only
  4. A gradient

Two models score 0.81 and 0.83 accuracy on 200 test examples. What is the most careful conclusion?

  1. The second model is clearly better
  2. The difference is within the sampling noise of a 200-example test set
  3. The first model is better
  4. Accuracy cannot be compared