ai/from-scratch

Stage 0 of 12 · about 2.8 h

The math toolkit

Floats, derivatives, logs and probability: exactly the math the path uses, in numpy.

Machine learning rests on four pieces of math, and this track teaches each one in code rather than on paper. You start with how computers store numbers and how numpy arrays let you compute on thousands of them at once. Then you learn what a derivative is and how to check one numerically, how exp and log turn scores into probabilities without overflowing, and how to score a model by the probability it gives to real data. Every lab runs in pocket/stage0/ and some use your own notes as data.

Before you start
You can write basic Python (variables, functions, loops, lists), run a script from a terminal, and do school arithmetic, including powers such as 3^2.
When you finish
pocket/stage0/ holds four working scripts, ending with probability.py, which fits a letter distribution to your notes and scores it by average negative log-likelihood against a uniform baseline.
Already know this? Skip it, or take the placement check. Skipped lessons stay open.
  1. Lesson 1 · 40 min

    Numbers and arrays

    Compare floats safely, replace a Python loop with one numpy operation, and predict the shape of a reshape, an axis sum and a broadcast before you run it.

  2. Lesson 2 · 40 min

    Slopes and derivatives

    Estimate a derivative with a finite difference, compute it with the power, sum and chain rules, and check one against the other in code.

  3. Lesson 3 · 40 min

    Exponentials and logs

    Use exp and log and their rules, turn scores into probabilities with sigmoid and softmax, and compute softmax and log-sum-exp without overflow.

  4. Lesson 4 · 45 min

    Probability basics

    Build a distribution from counts, sample from it with a seeded generator, compute conditional probabilities and expectations, and score a model by its average negative log-likelihood.