1  Introduction

1.1 Why this book exists

Most data science is done without much math, right up until it isn’t.

You can fit a model with one line of code. You can read the documentation, tune the hyperparameters, and get a number back. What you cannot do, without the math, is answer the questions that follow: why did this fail on my data, and what should I try next? Why does ridge shrink coefficients but Lasso zero them out? Why is my design matrix singular? Why does the loss oscillate when I raise the learning rate? Every one of those is a question about vectors, matrices, derivatives, or distributions wearing a disguise.

This book covers the math you actually reach for, and stops there. It is not a substitute for a proper linear algebra or analysis course, and it does not pretend to be. It is the working subset, explained in a way that sticks.

1.2 Who it’s for

You should be comfortable with high-school algebra and able to write basic R. That’s it. No prior linear algebra, no calculus, no probability theory is assumed. Where a symbol appears for the first time, it gets defined.

If you have seen this material before and it never quite landed, the geometry-first approach here may be what was missing.

1.3 How it’s organized

Five parts, in dependency order:

Foundations fixes notation and reviews sets and functions. Short, and worth skimming even if you know it — the notation conventions established there are used everywhere else.

Linear Algebra is the longest part and the one that pays off most. Vectors, matrices, linear systems, vector spaces, eigenvalues, and decompositions. By the end you will understand what PCA is doing and why least squares has the solution it does.

Calculus covers derivatives and integrals, then extends to functions of many variables and finally to matrix calculus — the notation that makes backpropagation tractable to write down.

Optimization puts the previous two parts to work. Convexity, gradient descent and its many descendants, and constrained problems.

Probability and Statistics covers random variables, the distributions you will actually meet, estimation, and inference.

1.4 How each section is built

Every concept gets the same treatment, in the same order:

  1. A plain-English definition first, then the formal one. Meaning before machinery.
  2. A worked example with small numbers, computed by hand so you can follow each step.
  3. Code in R that reproduces the example and then generalizes it.
  4. A visualization, because most of this material is geometric and seeing it once beats reading it three times.
  5. A note on where it shows up in machine learning, so the motivation is never more than a paragraph away.

Chapters end with exercises. Solutions are there, collapsed — try first.

1.5 Code and reproducibility

All code is in R and uses base R for the mathematics. There is a reason for that choice: solve(), %*%, crossprod(), svd(), and eigen() map almost one-to-one onto the notation, so the code reads like the math. Packages get in the way when the goal is to see the operation.

Visualizations use rtemis.draw. Figures are interactive — hover, zoom, and read values off them.

Every number printed in this book comes from code that runs when the book is built. Nothing is transcribed by hand.

NotePython and Julia

Python and Julia versions of the code are planned. The math does not change.

1.6 How to read it

Slowly, with a console open.

Reading math is not like reading prose — you are supposed to stop, re-read, and try the small case yourself. When a formula appears, the fastest way to understand it is to plug in the smallest example you can (two dimensions, integers) and see what comes out. Every worked example in this book was chosen to be small enough to do in your head.

If you get stuck on a section, skip it and keep going. Most things become obvious in retrospect, once you have seen what they are for.

1.7 Further reading

This book is deliberately narrow. When you want more depth:

  • Strang (2016) — the standard first course in linear algebra, geometric and readable.
  • Boyd and Vandenberghe (2018) — applied linear algebra with an engineering slant; free online.
  • Deisenroth et al. (2020) — closest in scope to this book, more formal; free online.
  • Boyd and Vandenberghe (2004) — the reference for convex optimization.
  • Wasserman (2004) — a fast, dense tour of statistical inference.
  • Hastie et al. (2009) and Goodfellow et al. (2016) — where this math gets used.