Mathematics for AI and Data Science
Twelve weeks with worked mathematics, diagrams, and Python labs, from vectors to a binary classifier.
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.
| Weeks | Question you’ll learn to answer | Checkpoint |
|---|---|---|
| 1–3 | What can this representation compare, change, or recover? | Explain what information is lost when two inputs produce the same output. |
| 4–6 | How do you approximate data and measure what the approximation loses? | Check a fitted line and quantify the error from keeping fewer matrix components. |
| 7–8 | How do you compute and trust a training update? | Check a derivative numerically, then predict whether a step will shrink or grow. |
| 9–12 | How 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
| Week | Lesson | What you’ll be able to do |
|---|---|---|
| 1 | Vectors, norms, and dot products | Read vectors as coordinates or features, calculate lengths and angles, and decide when magnitude matters. |
| 2 | Matrices as transformations | Use the columns of a matrix to understand what it does, then compose rotations and stretches in the right order. |
| 3 | Linear systems, rank, and projections | Tell when equations identify a unique answer and find the closest attainable output when the equations disagree. |
| 4 | Least squares and QR | Fit a line by minimizing squared error and use residual orthogonality to verify the solution. |
| 5 | Eigenvalues, covariance, and PCA | Derive the principal axes of a small dataset and measure how much variance a one-dimensional projection retains. |
| 6 | Singular value decomposition | See how singular directions compress a matrix and calculate the error left by a rank-one reconstruction. |
| 7 | Gradients, Jacobians, and the chain rule | Differentiate a two-input loss and use a numerical derivative to catch a wrong sign or a transposed Jacobian. |
| 8 | Hessians and gradient descent | Read curvature from a Hessian and predict whether a gradient descent step will converge or diverge. |
| 9 | Conditional probability and Bayes’ rule | Use natural frequencies to see how the same spam signal means different things at different base rates. |
| 10 | Expectation, variance, and covariance | Use paired outcomes to explain why the variance of a sum depends on how its parts move together. |
| 11 | Entropy, cross-entropy, and stable softmax | Measure the cost of a probability forecast and compute the loss without overflowing on large scores. |
| 12 | Capstone · Build a binary classifier from scratch | Derive 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.