Math Relearn/ Start here/ Module 00

Orientation: relearning math

Before any content: find out what you actually remember, and install the study method the whole notebook runs on. Twenty-five minutes now that will save you weeks later.

On this page
    Start here Β· Method

    00 Β· Orientation: relearning math

    ⏱ 25 minπŸ“Ž No code🎯 Retrieve before you read

    This module has two jobs and neither of them is "learn math". First: measure, honestly, what survived from your bachelor degree. Second: fix the way you will study it this time β€” because the reason it evaporated last time was not your brain, it was the method.

    By the end you can

    • Name the three passes β€” Remember β†’ Understand β†’ Implement β€” and say what each one is for.
    • Show which of the five core mathematical ideas you are weak in, from a cold diagnostic.
    • Explain why knowledge learned for an exam decays, and what retrieval practice does about it.
    • Set up the review rhythm (1 / 3 / 7 days) that keeps each module alive.

    Why this module exists

    Most engineers who "forgot the math" did not forget it β€” they never encoded it. Studying for a test with three days left is a pattern-matching activity: recognise the problem type, retrieve the recipe, execute, score. The recipe gets stored without its reason, and reasons are what survive. That is why you can still write a socket server from your computer-systems course (you used the idea for years) but cannot say what an eigenvector is for (you used it once, on paper, in June).

    So the fix is not "read a better textbook". The fix is to attach every idea to three things it never had before: a picture (what it looks like geometrically), a purpose (what problem humans had before it existed), and a place in ML (the exact line of code or the exact algorithm where it does work). Those three attachments are the entire design of this notebook.

    Pass 1

    Remember β€” retrieve before you read

    Do not scroll to the answers until you have written yours

    The method: three passes, then space it

    Every module in this notebook is built the same way, so the shape becomes automatic:

    1 Β· Remembercold retrieval β†’ 2 Β· Understandpicture + purpose β†’ 3 Β· Implementrun it, break it β†’ CheckpointMCQ + open questions β†’ Space it1 / 3 / 7 days
    1. Remember (retrieve, don't re-read). Each module opens with questions you try from memory, in writing before seeing any content. Wrong answers here are the most valuable thing in the notebook β€” they mark exactly where to pay attention.
    2. Understand (attach a picture and a purpose). For each idea: what problem existed before it, what it looks like, what breaks without it. If you cannot state an idea in one plain sentence, you have recognition, not understanding β€” keep going.
    3. Implement (make it move). Type the code β€” do not copy it. Then change one number, predict the effect, run it. The moment an abstraction produces an output you can see, it stops being a formula and becomes a tool.
    4. Checkpoint (prove it). Instant-feedback multiple choice plus open questions you answer aloud. Only then tick Mark done β€” and only if you can explain it without notes.
    5. Space it (make it stay). Re-open the module in 1 day, then 3, then 7. Ten minutes of recall on day three beats an hour of re-reading on day one.
    The forgetting curve, and why cold questions hurt

    Memory decays fast unless it is retrieved at the moment it is fading. That is why this notebook opens every module with discomfort: the struggle to half-remember is not a sign you are failing, it is the act that strengthens the trace. Studies of students consistently find that testing yourself outperforms re-reading by a wide margin, even when re-reading feels far more productive. Feeling fluent while reading is the illusion; feeling stuck while recalling is the work.

    Cold diagnostic: answer all 12 from memory

    Ten minutes. Write short answers β€” a word, a formula, a sketch. Do not look anything up, do not open the modules. Answers are in the recall cards below, but only after you have written yours; grading yourself against an answer you did not attempt is worthless.

    1. In words: what does $f(x) = x^2$ mean? Then compute $f(3)$ and $f(-2)$.
    2. Expand $(a+b)^2$. How about $(a+b)^3$?
    3. What is a vector? Give a real 3-dimensional example from a machine learning dataset.
    4. What does the dot product of two vectors measure?
    5. What is a matrix? Geometrically, what does multiplying a matrix by a vector do?
    6. What is a derivative, in one sentence?
    7. What is the gradient of $g(x,y) = x^2 + y^2$ at the point $(1,2)$? Which direction does it point?
    8. If $P(A) = 0.3$, $P(B) = 0.4$ and $A$, $B$ are independent, what is $P(A \cap B)$?
    9. What does $\mathbb{E}[X]$ mean? What is the expected value of a fair six-sided die?
    10. Correlation vs causation β€” one sentence each, and one sentence on why ML cares.
    11. Why do we maximise the log-likelihood instead of the likelihood itself?
    12. Name one ML algorithm and list the mathematical ideas you believe hold it together.

    What your answers mean

    There is no pass mark. Instead, note which group of questions felt hardest β€” that maps onto the five ideas every classical ML algorithm is assembled from:

    Cold questionsCore ideaIt becomes, in MLGo here
    1, 2Functions, parameters, structureHypothesis space, the model as $f(x;\theta)$Module 01
    3, 4, 5Linear algebraDataset = matrix, embeddings, PCA, attentionModule 02
    6, 7CalculusGradient descent, backpropagationModule 03
    8, 9, 11ProbabilityBayes classifier, MLE, calibrated predictionsModules 04, 06
    10, 12Statistics & evidenceEvaluation, A/B tests, generalisation claimsModule 05
    Machine learning is one equation β€” minimise a loss over parameters β€” and every module in this notebook is one of the tools needed to read, differentiate, or defend that equation.
    Pass 2

    Understand β€” the purpose of the whole journey

    Why this math, and why before deep learning

    What machine learning actually needs from mathematics

    Strip away the algorithms and every classical ML model is the same statement:

    $$\hat{\theta} = \arg\min_{\theta} \; \frac{1}{n}\sum_{i=1}^{n} L\big(f(x_i;\theta),\, y_i\big) + \lambda\,\Omega(\theta)$$ find the parameters ΞΈ that make the model's predictions least wrong, plus a penalty that keeps them sane

    That single line is why the syllabus looks the way it does. To read it you need the notation of Module 01. To build $f$ and understand why a matrix of weights can represent a dataset you need linear algebra (Module 02). To move $\theta$ downhill you need derivatives, gradients and the chain rule (Module 03). To know that minimising sum-of-squares is secretly assuming Gaussian noise, and that cross-entropy comes from coding theory, you need probability (Module 04) and information theory (Module 06). To decide whether your 0.91 beats someone else's 0.93 you need statistics (Module 05). To actually run the minimisation β€” and to understand what $\lambda$ is trading off β€” you need optimization (Module 07). Module 08 then reassembles the classic algorithms from these parts, and Module 09 shows the same parts reappearing, at larger scale, inside deep learning and agents.

    Why before deep learning

    Deep learning frameworks compute derivatives for you, so it is tempting to skip calculus. That works until something breaks β€” and it always breaks. When a loss explodes, when a layer saturates, when a transformer attends to nothing, when a fine-tune forgets what it knew: the diagnosis is always the same three suspects β€” a matrix behaving badly (linear algebra), a gradient vanishing or exploding (calculus + numerics), or a probability assumption that no longer holds. People who own the fundamentals debug in hours what others debug in weeks. This notebook is that ownership.

    How to read a formula from now on

    From Module 01 onward, treat every formula as a sentence with a grammar. When you meet one, ask the same five questions, in this order, every time:

    1. What are the objects? Scalars, vectors, matrices, functions, sets. Which letters are data, which are parameters, which are outputs?
    2. What is the shape? If $X$ is $n \times d$ and $w$ is $d$, then $Xw$ is length $n$ β€” one number per sample. Shape errors are 80% of implementation errors.
    3. What is being summed or averaged? Most ML formulas are an average over data points. A $\sum_i$ over samples is almost always "average the error".
    4. What is the direction of "good"? Minimise or maximise? Which term fights which? What does $\lambda$ trade off?
    5. Where does it live in code? Find the equivalent line in NumPy or scikit-learn. If you cannot find it, you have not understood it yet.
    Pass 3

    Implement β€” set up the workspace

    Ten minutes, once, and never again

    The environment check

    From Module 02 onwards every module has runnable code. Right now, confirm the three libraries everything depends on are installed and healthy:

    import numpy as np
    import matplotlib.pyplot as plt
    import sklearn
    
    print("numpy     ", np.__version__)
    print("sklearn   ", sklearn.__version__)
    
    # A 1-line sanity check you will reuse constantly:
    # dot product of a vector with itself = squared length
    v = np.array([3.0, 4.0])
    print("||v||^2 =", v @ v)          # expect 25.0
    print("||v||   =", np.linalg.norm(v))  # expect 5.0

    If those three lines run, you are ready. If not, fix it now β€” a broken environment two modules from now is the single most common reason people stop halfway.

    Exercise Β· 10 minutes
    • Write your diagnostic answers down (paper or a notes file). Put today's date on them. You will re-answer the same 12 questions after Module 09 β€” that comparison is your real score, not any quiz here.
    • Create one notes file per module, and inside it, only two sections: "The one-sentence version" and "Where I still get stuck". No copying of formulas β€” a formula you transcribe you will not keep; a formula you re-derive you will.
    • Book the rhythm: 25–40 focused minutes most days beats a 5-hour Sunday. Block it in your calendar now, including the 1 / 3 / 7-day reviews.
    Checkpoint

    Prove it, then start Module 01

    Answer first, then open the cards

    Multiple choice β€” instant feedback

    1. Your goal is to still understand gradient descent in six months. What does the learning-science evidence say works best?

    2. In this notebook, "Understand" a concept means…

    3. Which mathematical idea is the backbone of principal component analysis (PCA)?

    4. You just finished a module and everything made sense while reading it. What should you do next for that knowledge to survive?

    5. Which sequence does this notebook ask you to work in β€” and why that order?

    6. A dataset lives in a matrix $X$ with shape $(5000, 12)$. What does one row represent?

    Recall cards β€” the diagnostic answers

    Only open these once your own answers are written down.

    1–2. What is $f(x)=x^2$? And $(a+b)^2$, $(a+b)^3$?
    $f$ is a rule that turns an input into an output: square whatever you give it. $f(3)=9$, $f(-2)=4$ β€” note $f$ cannot tell $3$ from $-2$, a property that later matters a lot (many different inputs, same output β‡’ the inverse is not a function). $(a+b)^2 = a^2 + 2ab + b^2$ (not $a^2+b^2$ β€” the $2ab$ term is the single most common expansion error in ML derivations, e.g. when expanding squared errors in least squares). $(a+b)^3 = a^3 + 3a^2b + 3ab^2 + b^3$; coefficients come from Pascal's triangle, and the general case is the binomial theorem.
    3–4. What is a vector? What does the dot product measure?
    A vector is a list of numbers that belong together as one object β€” in ML, one data point. A customer might be $(\text{age}=34,\ \text{income}=52000,\ \text{clicks}=7)$: three coordinates, one point in 3-D space. The dot product $u \cdot v = \sum_i u_i v_i$ measures alignment: it is large and positive when the two vectors point the same way, zero when they are perpendicular (orthogonal β‡’ "no relationship"), negative when opposed. Geometrically $u\cdot v = \|u\|\|v\|\cos\theta$. This is why embeddings compare items by dot product β€” and why in Module 02 we will also normalise to remove length from the comparison.
    5. What is a matrix? What does matrix Γ— vector do?
    A matrix is a grid of numbers with two roles: a system of equations (each row one equation, each column one variable) and, better, a transformation. Multiplying a matrix $A$ by a vector $x$ produces a new vector β€” the image of $x$ under the transformation defined by $A$. It can rotate, scale, shear, project to fewer dimensions, or flip. The matrix $A$ with shape $d\times d$ maps $\mathbb{R}^d \to \mathbb{R}^d$; a $k\times d$ matrix maps $\mathbb{R}^d \to \mathbb{R}^k$, which is how a neural layer or PCA compresses 784 pixels into 50 features. In ML: your whole dataset is one matrix $X$ of shape $n\times d$.
    6–7. What is a derivative? Gradient of $x^2+y^2$ at $(1,2)$?
    A derivative is sensitivity: how much the output changes when you nudge the input. $f'(x)$ is the slope of the tangent line at $x$, and the best local linear approximation of $f$ near $x$. Machine learning uses it to answer "in which direction should I change the parameters to make the error smaller?" For $g(x,y)=x^2+y^2$: $\nabla g = (2x,\ 2y)$, so at $(1,2)$ the gradient is $(2,4)$. It points in the direction of steepest increase; gradient descent therefore steps in $-\nabla g = (-2,-4)$, and with learning rate $\eta=0.1$ the next point is $(1-0.2,\ 2-0.4) = (0.8,\ 1.6)$, closer to the minimum at the origin.
    8–9. $P(A\cap B)$ for independent events? $\mathbb{E}[X]$ and a fair die?
    Independence means one event tells you nothing about the other, so $P(A\cap B) = P(A)\,P(B) = 0.3 \times 0.4 = 0.12$. $\mathbb{E}[X]$ is the long-run average β€” the probability-weighted sum $\sum_x x\,P(X=x)$ (an integral for continuous variables). A fair die: $\tfrac{1}{6}(1+2+3+4+5+6) = 3.5$, which is not a value the die can take β€” expectation is a property of the process, not of any single outcome. In ML, $\mathbb{E}[L]$ is the population risk you actually care about, while your training loss is only one sample of it (that gap is Module 05's whole subject).
    10. Correlation vs causation?
    Correlation: two measured quantities tend to move together β€” a statement about joint data. Causation: intervening on one changes the other β€” a statement about what happens when you act. They diverge whenever a third variable drives both (ice-cream sales and drowning both rise in summer), or when the causal arrow is reversed. ML cares because models learn whatever pattern is in the data, including spurious ones. A credit model that "learns" that applicants from a certain postcode default more has found a correlation, and shipping it may be both unfair and fragile β€” the moment the world shifts, the pattern breaks. Prediction β‰  explanation; that distinction is why Module 05 exists.
    11. Why log-likelihood instead of likelihood?
    Three reasons, all practical: (1) products become sums β€” the likelihood of $n$ independent samples is a product $\prod_i p(y_i\mid x_i)$, which is numerically catastrophic (a million tiny numbers underflow to zero); the log turns it into $\sum_i \log p(y_i\mid x_i)$. (2) logs are monotone, so the argmax is unchanged β€” maximising the log finds the same best parameters. (3) derivatives get simpler β€” $\log$ kills products and turns powers into multiplications, which is why Gaussian MLE becomes "minimise squared error" and Bernoulli MLE becomes cross-entropy (Modules 04, 06 and 08 derive both properly).
    12. One algorithm and its mathematical skeleton
    Linear regression, as an example: a function family $f(x;w) = x^\top w$ (Module 01); the data as a matrix $X$ and the normal equations via matrix inversion / projections (Module 02); training by differentiating the squared error and stepping down the gradient (Module 03, 07); the squared-error loss being the maximum-likelihood estimate under Gaussian noise (Module 04); and its evaluation by confidence intervals and residual analysis (Module 05). Five modules, one algorithm β€” that overlap is not padding, it is the structure of the field. Module 08 does this decomposition for eight algorithms.

    Checkpoint β€” open questions

    Answer aloud, without notes. Short and honest is fine.

    1. Explain, to an imaginary colleague, why knowledge learned for an exam decays β€” and what retrieval practice changes.
    2. What are the three passes, and what is the specific purpose of each?
    3. Write the generic ML objective from memory. Which symbol is data? Which is parameters? Which is the regulariser?
    4. Name the five core ideas and one ML algorithm each one powers.
    5. When you next meet a formula you have never seen, what five questions will you ask it?
    6. What are your 1 / 3 / 7-day review dates for this module?
    Continue in your ML notebook

    The practical counterpart to this module is ML module 00 Β· Orientation & diagnostic, which does the same hole-finding for the modelling side. From here, the two notebooks interleave: this one explains why the math works, that one shows what the model does with it.