Mathematics for AI and Data Science

Twelve weeks with worked mathematics, diagrams, and Python labs, from vectors to a binary classifier.

Watch on YouTube

Work through the mathematics behind a small machine-learning model. Begin with vectors and finish by deriving, checking, and training a binary classifier in NumPy.

How to use these lessons

Basic algebra and enough Python to read a loop are good starting points. The lessons introduce the linear algebra, derivatives, and probability they use. Run each lab as a separate Python file. Install NumPy with python -m pip install numpy. The examples use Python 3 and NumPy, with small arrays and synthetic data.

Try the worked example on paper first. Then run the lab, compare its output with the page, and change one input in the practice exercise. Write down which result changed and why. The capstone asks you to carry those checks into a complete training run.

Start each week with its motivating problem. When you reach a formula, say what its inputs and output represent in the example before substituting numbers. In the lab, find the line that implements that calculation and check it against your hand result. If they disagree, check the units, array shapes, and which rows the calculation uses.

The four stages build on each other.

WeeksQuestion you’ll learn to answerCheckpoint
1–3What can this representation compare, change, or recover?Explain what information is lost when two inputs produce the same output.
4–6How do you approximate data and measure what the approximation loses?Check a fitted line and quantify the error from keeping fewer matrix components.
7–8How do you compute and trust a training update?Check a derivative numerically, then predict whether a step will shrink or grow.
9–12How do you turn predictions into probabilities and judge their quality?Derive a binary classifier, check its gradient, and compare its held-out loss against a baseline.

The 12 weeks

WeekLessonWhat you’ll be able to do
1Vectors, norms, and dot productsRead vectors as coordinates or features, calculate lengths and angles, and decide when magnitude matters.
2Matrices as transformationsUse the columns of a matrix to understand what it does, then compose rotations and stretches in the right order.
3Linear systems, rank, and projectionsTell when equations identify a unique answer and find the closest attainable output when the equations disagree.
4Least squares and QRFit a line by minimizing squared error and use residual orthogonality to verify the solution.
5Eigenvalues, covariance, and PCADerive the principal axes of a small dataset and measure how much variance a one-dimensional projection retains.
6Singular value decompositionSee how singular directions compress a matrix and calculate the error left by a rank-one reconstruction.
7Gradients, Jacobians, and the chain ruleDifferentiate a two-input loss and use a numerical derivative to catch a wrong sign or a transposed Jacobian.
8Hessians and gradient descentRead curvature from a Hessian and predict whether a gradient descent step will converge or diverge.
9Conditional probability and Bayes’ ruleUse natural frequencies to see how the same spam signal means different things at different base rates.
10Expectation, variance, and covarianceUse paired outcomes to explain why the variance of a sum depends on how its parts move together.
11Entropy, cross-entropy, and stable softmaxMeasure the cost of a probability forecast and compute the loss without overflowing on large scores.
12Capstone · Build a binary classifier from scratchDerive a binary classifier, check its gradient, and explain why scaling changes the behaviour of training.

What you’ll build

Weeks 1–6 turn vectors into transformations, projections, fits, and compressed representations. Weeks 7–8 connect gradients to optimization. Weeks 9–11 move from conditional probability to covariance and the cost of a probability forecast. Week 12 combines those pieces in a model with a numerical gradient check, a baseline, and a held-out test.

Further reading