Skip to the content.

Math for Machine Learning: The Free Roadmap to the Math You Actually Need (2027)

A practical, free guide to math for machine learning: exactly which parts of linear algebra, calculus, probability, statistics, optimization and information theory you need for ML and deep learning, in what order to learn them, how long each takes, and the best free books, courses and videos for every topic. It is written for programmers and career switchers who want to understand machine learning math well enough to read papers and debug models, without doing a full math degree first.

Last reviewed: December 2026.

Table of contents

How much math do you need?

It depends on what you want to do:

Goal Math needed Rough time from high-school math
Use ML libraries well (applied ML, data science) Vectors, matrices, derivatives as slopes, basic probability, descriptive statistics, evaluation metrics 6 to 10 weeks
ML engineer who trains and debugs neural networks Above + matrix calculus, chain rule/backpropagation, gradient descent variants, distributions, maximum likelihood, cross-entropy 3 to 5 months
Read and implement research papers Above + eigen/SVD decompositions, multivariate Gaussians, Bayesian inference, convex optimization basics, KL divergence 6 to 9 months
ML research / theory Above + real analysis, measure-theoretic probability, statistical learning theory, advanced optimization Years; a math or CS graduate program helps

The good news: most practical deep learning uses a small, repeated core. Matrix multiplication, the chain rule, gradients, probability distributions and log-likelihoods show up everywhere; you do not need to master every proof before building things.

The roadmap at a glance

Stage Topic Time (8-10 h/week) Must-know ideas
0 Pre-calculus refresher 1-2 weeks Functions, logs and exponentials, summation notation, sets
1 Linear algebra 4-6 weeks Vectors, dot products, matrix multiplication, linear maps, rank, eigenvectors, SVD, projections
2 Calculus + multivariable 4-6 weeks Derivatives, chain rule, partial derivatives, gradients, Jacobians, Hessians, Taylor approximation
3 Probability 4-6 weeks Random variables, common distributions, expectation, variance, conditional probability, Bayes’ rule, multivariate Gaussian
4 Statistics 3-4 weeks Estimators, maximum likelihood, bias-variance, confidence intervals, hypothesis tests, bootstrap
5 Optimization 2-3 weeks Gradient descent, SGD, momentum, Adam, convexity, Lagrange multipliers, regularization
6 Information theory 1-2 weeks Entropy, cross-entropy, KL divergence, mutual information
7 Integrate in ML books ongoing Derive linear regression, logistic regression, PCA, backprop, attention yourself

You do not have to go strictly in order. A good pattern is to learn linear algebra and calculus in parallel, then probability and statistics, and to start an ML course after Stage 2 so you see why the math matters.

Best picks (if you only use three resources)

  1. Mathematics for Machine Learning by Deisenroth, Faisal and Ong (free PDF from the authors, Cambridge University Press). Written exactly for this purpose: linear algebra, analytic geometry, matrix decompositions, vector calculus, probability and optimization, then applies them to regression, PCA, Gaussian mixtures and SVMs. Best single book.
  2. 3Blue1Brown video series Essence of Linear Algebra, Essence of Calculus and Neural Networks. Best for intuition; watch these before or alongside any textbook.
  3. Harvard Stat 110 (Joe Blitzstein) with the free online book Introduction to Probability. Best probability course, with famous problem sets.

Add Khan Academy for any gaps in prerequisites.

Stage 0: Pre-calculus refresher

Why it matters for ML: logs turn products of probabilities into sums (log-likelihood), exponentials appear in softmax and sigmoid, and summation notation is how every loss function is written.

What to know:

Resources:

Check yourself: can you simplify log(e^(2x) · e^3), and write the mean squared error of n predictions with ∑ notation?

Stage 1: Linear algebra

Why it matters for ML: data is stored as matrices (rows are examples, columns are features), every neural network layer is a matrix multiplication plus a nonlinearity, embeddings are vectors, attention is built from dot products, PCA is an eigendecomposition, and low-rank methods such as LoRA are matrix factorizations.

What to learn (in order)

  1. Vectors, addition, scaling, norms (L1, L2), dot product and cosine similarity.
  2. Matrices as linear transformations; matrix-vector and matrix-matrix multiplication; transpose.
  3. Systems of linear equations, Gaussian elimination, inverse, determinant (as volume scaling).
  4. Span, linear independence, basis, rank, column space and null space.
  5. Orthogonality, projections, least squares (this is linear regression).
  6. Eigenvalues and eigenvectors; diagonalization; symmetric matrices and the spectral theorem.
  7. Positive (semi)definite matrices (covariance matrices are one).
  8. Singular value decomposition (SVD) and low-rank approximation.
  9. Practical numerics: broadcasting, batched matrix multiplication, condition numbers.

Resources

Resource Type Cost Why
3Blue1Brown: Essence of Linear Algebra Videos (~3 h) Free Start here. Geometric intuition for every core idea.
MIT 18.06 Linear Algebra (Gilbert Strang) Full course Free The classic university course with lectures, problem sets and exams.
MIT 18.06SC (scholar version) Self-paced course Free Same material packaged for self-study with recitation videos.
Introduction to Applied Linear Algebra (VMLS) by Boyd and Vandenberghe Book Free PDF Best book for ML practitioners. Vectors, matrices, least squares, with data-fitting and classification applications. Julia and Python companions.
Linear Algebra Done Right by Sheldon Axler Book Free (open access, 4th edition) Proof-based and elegant; for when you want deeper understanding.
Immersive Linear Algebra Interactive book Free Interactive figures for building intuition.
MIT 18.065 Matrix Methods in Data Analysis, Signal Processing, and Machine Learning Course Free (book is paid) Strang’s follow-up focused on SVD, low rank, and deep learning.
Khan Academy Linear Algebra Videos + exercises Free Gentle pace with practice.
fast.ai Computational Linear Algebra Notebooks Free Linear algebra through NumPy code and real applications.

Best pick: 3Blue1Brown first, then VMLS for applied practice; add MIT 18.06 if you want the full university experience.

Exercises

Stage 2: Calculus and multivariable calculus

Why it matters for ML: training a model means minimizing a loss function, and gradient descent needs the gradient of that loss with respect to millions of parameters. Backpropagation is just the chain rule applied efficiently on a computation graph.

What to learn

  1. Limits informally; the derivative as rate of change and as best linear approximation.
  2. Derivative rules: product, quotient, chain rule. Derivatives of exp, log, sigmoid, tanh.
  3. Integrals as areas and accumulations (needed for probability densities and expectations).
  4. Partial derivatives and the gradient; directional derivatives.
  5. Jacobian (vector-valued functions) and Hessian (second derivatives, curvature).
  6. Multivariable chain rule; computation graphs.
  7. Matrix calculus: derivatives of xᵀAx, ‖Ax − b‖², softmax and cross-entropy.
  8. Taylor series and linear/quadratic approximations (the basis of Newton’s method).
  9. Automatic differentiation: forward mode vs reverse mode.

Resources

Resource Type Cost Why
3Blue1Brown: Essence of Calculus Videos Free Start here for intuition.
Khan Academy Calculus 1, 2 and Multivariable Videos + exercises Free The multivariable unit (taught by Grant Sanderson) is ideal for gradients and Jacobians.
MIT 18.01SC Single Variable Calculus Course Free Full self-study course.
MIT 18.02SC Multivariable Calculus Course Free Gradients, optimization in several variables.
OpenStax Calculus Volumes 1-3 Textbook Free (CC BY-NC-SA) Complete textbook with exercises and answers.
The Matrix Calculus You Need For Deep Learning by Terence Parr and Jeremy Howard Article Free Best bridge from school calculus to neural network gradients.
Matrix Calculus for Machine Learning and Beyond (MIT 18.S096) Course Free Treats derivatives as linear operators; excellent for autodiff understanding.
The Matrix Cookbook Reference PDF Free Look-up table of matrix identities and derivatives.
Andrej Karpathy: The spelled-out intro to neural networks and backpropagation (micrograd) Video Free Builds a tiny autodiff engine from scratch.

Exercises

Stage 3: Probability

Why it matters for ML: models output probabilities, losses are negative log-likelihoods, generative models (VAEs, diffusion, language models) are probability distributions, and uncertainty, sampling and Bayesian methods are all probability.

What to learn

  1. Sample spaces, events, axioms; counting basics.
  2. Conditional probability, independence, the law of total probability, Bayes’ rule.
  3. Discrete random variables: Bernoulli, binomial, categorical, Poisson, geometric.
  4. Continuous random variables: uniform, normal (Gaussian), exponential, beta, gamma.
  5. Expectation, variance, covariance, correlation; linearity of expectation.
  6. Joint, marginal and conditional distributions.
  7. The multivariate Gaussian and its covariance matrix (links back to linear algebra).
  8. Law of large numbers and the central limit theorem.
  9. Sampling methods: Monte Carlo estimates, importance sampling, an introduction to Markov chains and MCMC.

Resources

Resource Type Cost Why
Harvard Stat 110 with Introduction to Probability (free online) by Blitzstein and Hwang Lectures + book Free Best pick. Intuitive, story-driven, with hundreds of exercises and solutions to many.
MIT RES.6-012 Introduction to Probability by John Tsitsiklis Course Free Rigorous, clear lectures with problem sets.
Seeing Theory Interactive Free Visual, interactive introduction to probability and statistics from Brown University.
Khan Academy Statistics and Probability Videos + exercises Free Gentle foundation.
Probability Theory: The Logic of Science by E. T. Jaynes Book Paid Classic Bayesian perspective; advanced.
Probabilistic Machine Learning: An Introduction by Kevin Murphy Book Free PDF from author (MIT Press) Probability chapters written specifically for ML.
Think Bayes by Allen Downey Book Free (CC license) Bayesian statistics through Python code.

Exercises

Stage 4: Statistics

Why it matters for ML: training is estimation, evaluation is inference, and A/B tests decide which model ships. Understanding variance, overfitting and uncertainty in metrics separates good practitioners from lucky ones.

What to learn

  1. Descriptive statistics, distributions of data, visualizing data.
  2. Estimators, bias, variance, mean squared error; the bias-variance tradeoff.
  3. Maximum likelihood estimation (MLE), and maximum a posteriori (MAP) as MLE plus a prior (regularization).
  4. Sampling distributions, standard errors, confidence intervals.
  5. Hypothesis testing, p-values, multiple comparisons, statistical power; A/B testing.
  6. Bootstrap and permutation tests.
  7. Linear and logistic regression from a statistical viewpoint.
  8. Cross-validation and why test sets must stay untouched.
  9. Basic Bayesian inference: priors, posteriors, conjugacy, credible intervals.

Resources

Resource Type Cost Why
An Introduction to Statistical Learning (ISLR / ISLP) by James, Witten, Hastie, Tibshirani (and Taylor for the Python edition) Book + videos Free PDF from authors Best pick to connect statistics with ML; R and Python editions.
OpenIntro Statistics Book Free PDF (pay what you want) Clear intro to inference with exercises.
Think Stats by Allen Downey Book Free Exploratory statistics through Python.
StatQuest with Josh Starmer Videos Free Short, very clear explanations of statistical and ML concepts.
Statistical Rethinking by Richard McElreath Lectures (book is paid) Free lectures The best course on Bayesian modeling and causal thinking.
The Elements of Statistical Learning by Hastie, Tibshirani, Friedman Book Free PDF The advanced follow-up to ISL.
All of Statistics by Larry Wasserman Book Paid Dense, fast tour of statistics for CS and ML students.

Exercises

Stage 5: Optimization

Why it matters for ML: every training run is an optimization problem. Knowing how optimizers behave helps you choose learning rates, diagnose divergence, and understand why Adam, weight decay and learning-rate schedules work.

What to learn

  1. Gradient descent and the effect of the learning rate; convergence on a quadratic.
  2. Stochastic and mini-batch gradient descent.
  3. Momentum, Nesterov, RMSProp, Adam and AdamW.
  4. Convex sets and functions; why convex problems have no bad local minima.
  5. Constrained optimization: Lagrange multipliers, KKT conditions (needed for SVMs).
  6. Second-order methods: Newton’s method, quasi-Newton (L-BFGS).
  7. Regularization (L1, L2), early stopping, and learning-rate schedules (warmup, cosine decay).

Resources

Resource Type Cost Why
Convex Optimization by Boyd and Vandenberghe Book Free PDF The standard text; read chapters 1-5 and 9.
Stanford EE364A Course Free materials and lecture videos The course that goes with the book.
Why Momentum Really Works (Distill) by Gabriel Goh Interactive article Free Beautiful interactive explanation of momentum.
An overview of gradient descent optimization algorithms by Sebastian Ruder Article Free Clear survey of SGD variants and Adam.
Dive into Deep Learning: Optimization Algorithms chapter Book chapter Free Optimizers with runnable code.
Numerical Optimization by Nocedal and Wright Book Paid Advanced reference on algorithms.

Exercises

Stage 6: Information theory

Why it matters for ML: cross-entropy is the loss of nearly every classifier and language model, KL divergence appears in VAEs, knowledge distillation and RLHF, and perplexity is exponentiated cross-entropy.

What to learn

  1. Information content and entropy; bits vs nats.
  2. Cross-entropy and its link to negative log-likelihood.
  3. KL divergence: asymmetry, non-negativity, forward vs reverse KL.
  4. Mutual information and conditional entropy.
  5. Perplexity for language models.

Resources

Resource Type Cost Why
Information Theory, Inference, and Learning Algorithms by David MacKay Book Free PDF for on-screen viewing Classic, ML-flavored, with lectures on the same site.
Visual Information Theory by Chris Olah Article Free Best intuition for entropy, cross-entropy and KL.
Elements of Information Theory by Cover and Thomas Book Paid The standard graduate reference.
Deep Learning book, chapter 3 Book chapter Free online Probability and information theory in a few dense pages.

Exercises

Stage 7: Putting it together in ML books

Once the basics are in place, these free books use all of it and are where the math starts to pay off:

Book Level Free? Notes
Mathematics for Machine Learning Beginner to intermediate Free PDF Part II derives linear regression, PCA, GMMs and SVMs.
Dive into Deep Learning (d2l.ai) Beginner to intermediate Free Math appendix plus runnable PyTorch/JAX code for everything.
Understanding Deep Learning by Simon J. D. Prince Intermediate Free PDF from author Clear modern treatment with notebooks; excellent figures.
Deep Learning by Goodfellow, Bengio, Courville Intermediate Free online Part I is a compact math refresher for DL.
Deep Learning: Foundations and Concepts by Christopher and Hugh Bishop Intermediate to advanced Free online version Modern, rigorous, includes transformers and diffusion.
Pattern Recognition and Machine Learning by Christopher Bishop Advanced Free PDF from Microsoft Research Classic probabilistic ML.
Probabilistic Machine Learning (books 1 and 2) by Kevin Murphy Advanced Free PDFs Encyclopedic reference.
Patterns, Predictions, and Actions by Hardt and Recht Intermediate Free Concise, modern, with a strong statistical viewpoint.

Challenge: by the end, derive each of these on paper: linear regression (normal equation), logistic regression gradient, PCA via eigendecomposition, backpropagation through a two-layer MLP, softmax cross-entropy gradient, and scaled dot-product attention with shapes.

Topic-to-ML map

Math topic Where it shows up in ML
Dot product, cosine similarity Embeddings, semantic search, attention scores
Matrix multiplication Every dense layer, attention, convolution (as im2col)
Eigendecomposition, SVD PCA, spectral clustering, LoRA intuition, recommender systems
Norms Regularization (L1 = sparsity, L2 = weight decay), gradient clipping
Chain rule, Jacobians Backpropagation, autodiff
Gradients and Hessians Optimizers, learning-rate choice, loss-landscape curvature
Bayes’ rule Naive Bayes, Bayesian inference, posterior-based uncertainty
Gaussian distribution Linear regression noise, weight initialization, VAEs, diffusion models
Categorical distribution + softmax Classifiers, next-token prediction in LLMs
Maximum likelihood Almost every loss function (MSE, cross-entropy)
KL divergence VAEs, distillation, RLHF and DPO regularization
Expectation and sampling Stochastic gradients, Monte Carlo, dropout, LLM sampling (temperature, top-p)
Convexity Why linear and logistic regression are easy, and deep nets are not
Hypothesis testing, confidence intervals Comparing models, A/B tests, benchmark noise

Free books compared

Book Linear algebra Calculus Probability Statistics Optimization Proofs Best for
Mathematics for Machine Learning Yes Yes (vector calculus) Yes Some Yes Moderate One-book overview
Introduction to Applied Linear Algebra (VMLS) Yes No No Some (least squares) Some Light Practical linear algebra
Linear Algebra Done Right Yes (deep) No No No No Heavy Mathematical maturity
Introduction to Probability (Blitzstein-Hwang, free online) No Uses it Yes (deep) Some No Moderate Probability
ISLR / ISLP No No Light Yes Light Light Statistics for ML
Convex Optimization Uses it Uses it No Some Yes (deep) Heavy Optimization
Information Theory, Inference, and Learning Algorithms No Uses it Yes Bayesian No Moderate Information theory

Video courses compared

Course Length Style Best for
3Blue1Brown series Hours Animated intuition Everyone, first
MIT 18.06 ~35 lectures Chalkboard lectures Thorough linear algebra
Harvard Stat 110 ~35 lectures Lectures + strategic practice Probability
Mathematics for Machine Learning Specialization (Imperial College London, Coursera) 3 courses Short videos + Python quizzes Guided path; audit free, certificate paid
Mathematics for Machine Learning and Data Science (DeepLearning.AI, Coursera) 3 courses Beginner-friendly + labs Absolute beginners; certificate paid
Khan Academy Self-paced Exercises with instant feedback Filling gaps
StatQuest Short videos Simple, step-by-step Statistics and ML concepts

Exercises and projects

Math sticks when you implement it. Build these in plain NumPy (no ML libraries) and compare against scikit-learn or PyTorch at the end:

  1. Linear regression three ways: normal equation, gradient descent, and SGD. Plot the loss curves. (Linear algebra, calculus, optimization.)
  2. Logistic regression from scratch on a binary dataset, with L2 regularization and a numeric gradient check. (Calculus, probability, MLE.)
  3. PCA and image compression using SVD on a face or MNIST dataset. (Linear algebra.)
  4. Naive Bayes spam classifier with Laplace smoothing. (Probability, Bayes’ rule.)
  5. Gaussian mixture model with EM, visualizing the ellipses at each iteration. (Probability, multivariate Gaussians, optimization.)
  6. A two-layer neural network with manual backprop trained on MNIST. (Matrix calculus.)
  7. Optimizer race: SGD, momentum, RMSProp, Adam on the same small network. (Optimization.)
  8. Bootstrap your model’s accuracy and report a confidence interval instead of one number. (Statistics.)
  9. Self-attention by hand: write scaled dot-product attention with shapes annotated and check against PyTorch. (Linear algebra, softmax.)
  10. Tiny language model: a character-level bigram model, then measure cross-entropy and perplexity. (Probability, information theory.)

Study plans (8 weeks, 4 months, 9 months)

Fast track: 8 weeks (applied ML)

Week Focus
1 3Blue1Brown Essence of Linear Algebra; NumPy matrix practice
2 VMLS chapters on vectors, matrices, least squares
3 3Blue1Brown Essence of Calculus; derivatives and chain rule
4 Khan Academy gradients; “The Matrix Calculus You Need For Deep Learning”
5 Probability basics (Seeing Theory, Stat 110 first lectures)
6 Distributions, expectation, Bayes’ rule
7 Statistics: MLE, bias-variance, cross-validation (ISL chapters 2 and 5)
8 Projects 1 and 2 from the list above

Standard: 4 months (ML engineer)

Deep: 9 months (reading papers)

Common mistakes

FAQ

Do I need math to learn machine learning? To use libraries, only a little. To understand why models work, debug training, or read papers, yes: linear algebra, calculus, probability and statistics are the core.

What is the most important math for machine learning? Linear algebra and probability are the two pillars, followed closely by multivariable calculus (for gradients) and statistics (for evaluation).

Can I learn math for machine learning for free? Yes. Every core topic here has an excellent free option: Mathematics for Machine Learning, VMLS, MIT OpenCourseWare, Harvard Stat 110, ISL and Boyd’s Convex Optimization are all legally free.

How long does it take to learn math for ML? About 2 months part time for applied ML basics, 4 months for confident ML engineering, and 6 to 9 months to read most papers comfortably.

Is Mathematics for Machine Learning (the book) good for beginners? It is great if you remember high-school algebra and some calculus. If not, do a few weeks of Khan Academy and 3Blue1Brown first.

Do I need real analysis or measure theory? Not for applied ML or ML engineering. They matter for theoretical research and some advanced probability.

Is calculus or linear algebra more important for deep learning? You need both, but you will use linear algebra every day (shapes, matrix products) while calculus is mostly handled by autodiff. Understanding the chain rule still matters for debugging.

What math do I need for LLMs and transformers? Matrix multiplication, softmax, dot-product attention, layer normalization (mean and variance), cross-entropy and perplexity, and basic sampling. Fine-tuning methods add low-rank factorization (LoRA) and KL divergence (RLHF, DPO).

I am bad at math. Can I still do ML? Yes. Most people who “are bad at math” had poor teaching or gaps in prerequisites. Start at Stage 0, go slowly, and code everything to make it concrete.

Should I learn math with Python? Yes. NumPy, Matplotlib and SymPy turn abstract ideas into experiments you can see. Many resources above (VMLS, Think Stats, Think Bayes, d2l.ai) are built around code.

Where to go next

Contributing

Contributions are welcome. Please:

License

Content is licensed under CC BY 4.0.

If this helped you, a star helps others find it.

More free resources

Part of the Ralpberry Labs open-source collection. See also Top 100 Open Source.