Mathematics for Machine Learning
Master the math behind ML with interactive 2D and 3D visualizations
New · 3-D labs
Don't just read the math — play it.
16 3-D mini-games: roll optimizers down a loss landscape, train a network live, generate shapes from noise, fly through a galaxy of words and bend space with a matrix.
Enter the lab40 chapters, one story
0 of 167 lessons touched. Choose a chapter to explore its lessons.
- 01
Introduction and Motivation
Machine learning is, at its core, a mathematical conversation with data. When you train a neural network, fit a regression model, or cluster…
UnlocksSets the stage- loss landscapes
- gradient descent
- model fitting
- 02
Linear Algebra
A system of linear equations is a collection of equations in which each unknown appears only to the first power and is never multiplied by a…
UnlocksPowers every model- MLPs
- embeddings
- linear layers
- 03
Analytic Geometry
A norm on a vector space is a function that assigns each vector a non-negative length. Formally, it must satisfy three axioms: absolute homo…
UnlocksLets distances mean something- k-NN
- cosine similarity
- kernel methods
- 04
Matrix Decompositions
The determinant of a square matrix is a single scalar that captures the signed volume scaling factor of the linear map . If , the map triple…
UnlocksUnlocks PCA & SVD- PCA
- recommender systems
- low-rank attention
- 05
Calculus
The derivative of a function measures its instantaneous rate of change at . Formally, . Geometrically, it is the slope of the tangent line t…
UnlocksMakes training possible- backprop
- autograd
- neural training
- 06
Probability and Distributions
A probability space is a mathematical stage for reasoning about uncertainty. It consists of three ingredients: a sample space (the set of al…
UnlocksQuantifies uncertainty- softmax
- Bayesian inference
- calibration
- 07
Continuous Optimization
Gradient descent is the simplest and most-used continuous optimization algorithm: to minimize a differentiable , start at some and iterative…
UnlocksTrains the model- SGD
- Adam
- Lagrangian methods
- 08
When Models Meet Data
The previous seven chapters built a mathematical toolbox. Chapter 8 turns the key and opens the door to machine learning proper. Three ingre…
UnlocksFrames learning as inference- train/test split
- regularization
- cross-validation
- 09
Linear Regression
Linear regression is the first and most important supervised learning algorithm. The model asserts that the target is a linear function of f…
UnlocksCloses the loop on regression- OLS
- ridge
- Bayesian linear regression
- 10
Principal Component Analysis
Principal Component Analysis (PCA) is the most-used dimensionality reduction technique and a perfect payoff for everything learned in linear…
UnlocksCompresses high-dim data- PCA
- whitening
- eigenfaces
- 11
Gaussian Mixture Models
A Gaussian Mixture Model (GMM) assumes the data is generated by underlying clusters, each Gaussian with its own mean and covariance: where a…
UnlocksPowers soft clustering- GMM
- EM algorithm
- soft clustering
- 12
Support Vector Machines
Support Vector Machines (SVMs) solve binary classification by finding the maximum-margin hyperplane that separates two classes. Given labele…
UnlocksBuilds robust classifiers- SVM
- kernel SVM
- hinge loss
- 13
Deep Learning Foundations
Every classifier in modern deep learning ends with the same two-step ritual: turn raw scores into probabilities with softmax, then measure t…
UnlocksBridges to deep learning- MLPs
- activation functions
- backpropagation
- 14
Deep Learning Building Blocks
A convolution slides a learnable filter across an input feature map and outputs, at each spatial position, the dot product between the filte…
- 15
Generative Models
A VAE is a generative model that learns to compress data into a continuous latent space and decode latents back into data. Two networks: an…
- 16
Reinforcement Learning
A Markov Decision Process (MDP) formalizes sequential decision-making. It's the tuple : state space , action space , transition probabilitie…
- 17
Classical ML & Evaluation
A decision tree is a sequence of axis-aligned splits that partitions feature space into rectangles. At each leaf the model predicts the majo…
- 18
Information Theory
Shannon entropy turns a probability distribution into a single number that quantifies its unpredictability — the average bits of surprise pe…
UnlocksDefines every loss- cross-entropy loss
- KL divergence
- InfoNCE
- 19
Numerical Methods for ML
Computers can't represent most real numbers exactly. Knowing the shape of float32 — and what breaks when you ignore it — is the difference b…
UnlocksKeeps math stable- stable softmax
- mixed precision
- well-conditioned linear systems
- 20
Statistical Learning Theory
Every model's expected error decomposes into three terms — bias, variance, and irreducible noise. Knowing which one dominates tells you whet…
UnlocksExplains why models generalize- bias-variance
- VC dimension
- PAC bounds
- 21
Variational Inference and Generative Models
The ELBO is the single objective that makes variational autoencoders, Bayesian deep learning, and most modern generative models trainable —…
UnlocksPowers VAEs & diffusion- VAE
- Stable Diffusion
- DDPM
- 22
Markov Chains and Monte Carlo
A Markov chain is a memoryless random walk on a state space — and its stationary distribution is the universal target of MCMC, the convergen…
UnlocksDrives Bayesian inference & RL- MCMC
- HMC / NUTS
- particle filters
- 23
Fourier Analysis and Tensor Algebra
Any reasonable periodic function can be written as a sum of sines and cosines — the Fourier series. This single change of basis powers JPEG,…
UnlocksBackbones audio, vision & transformers- FFT / spectrograms
- Whisper
- multi-head attention
- 24
Statistics & Optimization Foundations
Hypothesis tests and confidence intervals turn finite samples into rigorous statements about populations — the same machinery that powers A/…
UnlocksMakes evaluation & training rigorous- bootstrap CIs
- L-BFGS
- natural gradient
- 25
Python for ML: Code the Math
Set up Python, meet NumPy, and learn the one rule that makes machine-learning code fast: vectorize everything. Every cell in this chapter ru…
UnlocksTheory → working code- NumPy
- Pyodide in-browser
- PCA from scratch
- 26
Probabilistic Graphical Models
A Bayesian network factorizes a giant joint distribution into a directed graph of small conditional tables — turning an exponential problem…
- 27
Gaussian Processes & Kernels
A kernel is a similarity function that secretly computes an inner product in a (possibly infinite-dimensional) feature space — letting linea…
- 28
Causal Inference
A hidden common cause can make two variables move together even when neither causes the other — confounding is why observational correlation…
- 29
Divergences, Line Search & Bayesian Approximation
KL divergence is asymmetric and can blow up to infinity. The Jensen-Shannon divergence symmetrizes it and stays bounded by log 2 — one membe…
- 30
Probability & Linear-Algebra Foundations You Reuse
Six identities — linearity of expectation, Var(aX+b)=a²Var(X), the variance-of-a-sum rule, and the covariance/correlation definitions — do 9…
- 31
Deep Learning in Practice
Training a neural network reduces to one question repeated millions of times: how should I nudge each parameter to make the loss smaller? Th…
- 32
Modern Architectures & Decisions
The core question. A sequence model must let each token gather information from other tokens. Recurrent networks (RNNs) do this by passing a…
- 33
PCA Revisited: Projection and Latent Variables
The second face of PCA: project data onto a low-dimensional subspace so that the reconstruction error is as small as possible — and discover…
- 34
The Mathematics of Model Adaptation
Fine-tune a billion-parameter model by training two thin matrices per layer: the rank factorization ΔW = BA turns a 16M-number update into 6…
- 35
Calculus Foundations: From Zero to Hero
Every idea in calculus — derivatives, integrals, all of it — is built on one concept: the limit. Start here, from nothing.
- 36
Calculus in Python: Numerical and Symbolic Methods
Turn the limit definition of the derivative into code — approximate it with finite differences, watch the error shrink (and, eventually, gro…
- 37
Statistics Foundations: From Zero to Hero
Every statistic you compute from data is itself a random variable with its own distribution — this lesson builds that idea from a tiny, full…
- 38
Probability and Statistics in Python
Flip a simulated coin thousands of times and watch the proportion of heads settle toward the true probability — the Law of Large Numbers mad…
- 39
Calculus Foundations II: Applications, Sequences, and Series
Chapter 29 taught you the area UNDER one curve. Two natural extensions: the area BETWEEN two curves, and — by spinning a region around an ax…
- 40
Statistics Foundations II: Regression and Comparing Groups
Chapter 31 asked questions about ONE variable. This lesson asks: how do TWO variables move together, and can you draw a line through them th…