skipnothing/Math for Machine Learning

Math for Machine Learning

Linear algebra, calculus, statistics, and probability, the mathematical language behind ML algorithms.

You'll need basic algebra, variables, equations, x/y plots.

Loading…
01

Linear Algebra

Scalars, vectors, matrices, and the directions that matter

4/4
#1

Scalars, Vectors & Matrices

Name a block of numbers as a scalar, vector, or matrix from its layout alone, state its shape without counting entries, and judge whether two shapes line up along a chosen axis before any arithmetic runs.

A thermostat shows one number, a receipt shows a line of them like `[3.50, 2.20, 1.80]`, and a spreadsheet shows a whole grid. Same digits, but the layout alone decides what they mean and which ones your code can combine.

12 min
#2

Matrix Operations

Predict from the shapes alone whether an addition, transpose, or multiply is even legal and what shape it returns, then build a single product cell by pairing one row against one column and summing.

Stack two weekly sales spreadsheets of the same size and you can total them square by square; stack two of clashing sizes and the exact same command, written `week1 + week2` in code, refuses before it adds a single figure.

15 min
#3

Dot Product & Norms

Score how alike two vectors are by pairing their entries and summing, read direction straight off that number's sign, measure a vector two ways with the L1 and L2 norms, and strip length away to leave cosine similarity on a fixed minus-one-to-one scale.

Two friends each rate the same three snacks out of ten, and you want one number for how alike their taste runs; multiply the ratings in pairs, add them up, and `a . b` already holds it.

14 min
#4

Eigenvalues & Eigenvectors

Hunt the few directions a matrix leaves on their own line, read each eigenvalue as a signed stretch factor where positive stretches, negative flips, and zero collapses the line, and see why a data cloud's eigenvectors fall along its natural axes.

Push a plane of arrows through the same matrix and almost every one swings to a new heading, yet a stubborn few, like the arrow reaching to `[2, 1]`, come out pointing exactly the way they went in, only longer.

18 min
02

Calculus for ML

Derivatives, gradients, and the chain rule, how models find the bottom

6/6
#5

Functions & Graphing

Read a graph as the rule that produced it, separate the inputs a function accepts from the outputs it produces, and tell a straight rule from a bending one by whether equal input steps lift the output equally, then read that same shape in a training loss curve.

Feed 20 into the rule `C × 9/5 + 32` and exactly one number falls out: 68. Plot every input beside its output and the rule stops being arithmetic, it becomes a shape you can read at a glance.

10 min
#6

Derivatives & Slope

Shrink a secant until it settles into the tangent to read a curve's slope at one point, differentiate polynomials term by term with the power rule, and step against the slope's sign to walk a loss curve downhill.

Walk a curved hillside and the ground tilts differently under every footstep; the height follows a rule as plain as `x**2`, yet its steepness keeps shifting, and pinning that steepness to one exact spot is the whole move here.

14 min
#7

Partial Derivatives

Freeze every input but one so a multi-input surface collapses to an ordinary curve, read the partial derivative as that slice's slope, and give each model parameter its own partial of the error.

Stand on a hill whose height obeys `f(east, north)` and ask how steep the ground is; it answers with a question, steep which way? Face north, then face east, and the same spot gives two different answers.

14 min
#8

The Chain Rule

Multiply the local slopes of nested stages to get a composition's slope, evaluate each outer slope at the value its inner stage produced, and read the same product stacked deep as the backpropagation a network runs to reach every weight.

Turn one dial and it drives a second stage, then a third, so the machine's response to your turn is every stage's response multiplied down the line, the exact arithmetic a network runs the moment `loss.backward()` fires.

16 min
#9

Gradients & Directional Derivatives

Stack a point's partial derivatives into the gradient arrow, read its direction as the steepest way uphill and its length as the climb rate, then flip its sign to step a loss surface downhill.

Last topic you measured a hill's steepness one axis at a time, north then east, landing two numbers like `(+8, -3)`, yet neither points the steepest way to walk. Stack them into one arrow and it aims straight uphill.

14 min
#10

Integrals (Basics)

Sum a rate curve's thin strips until the running total settles on one exact area, then point the same summing at a probability density so the area between two marks becomes the chance of landing there.

A speedometer holding at `20` meters a second for five seconds puts you 100 meters down the road, a plain width times height. Let the needle drift and that tidy rectangle buckles into a curved patch you have to rebuild.

12 min
03

Statistics & Distributions

Variance, bell curves, and the shapes data takes

6/6
#11

Mean, Median, Mode

Pick mean, median, or mode by the shape of the data, predict which one an outlier drags and which one holds, and read the mean-median gap as a numerical measure of skew.

Six salaries, `[52, 55, 58, 60, 64, 240]`, and two honest people report the typical pay as $88k and $59k. Both did the arithmetic right; the number you trust depends on which question you asked.

14 min
#12

Variance & Standard Deviation

Square each value's gap from the mean into the variance, square-root it back to a standard deviation in the data's own units, then rescale any value to a mean-zero, standard-deviation-one z-score for feature preprocessing.

Two classes both average 75 on one test, `[73, 74, 75, 76, 77]` and `[55, 65, 75, 85, 95]`. By that average they look identical, yet one class is ten times more spread out than the other.

14 min
#13

Normal Distribution

Pin a bell curve down with just two numbers, a center and a width, apply the 68-95-99.7 rule to turn any standard-deviation band into a percentage of the data, and read a value's percentile by standardizing it onto the single standard normal, then catch where skewed data breaks the rule.

Line up the heights of a thousand adult men and they pile into a smooth hump: most crowd near `69` inches, thinning fast toward the very tall and the very short. Two numbers describe that whole pile.

14 min
#14

Binomial Distribution

Tally the successes in `n` independent yes/no trials at a constant rate `p`, read the center `np` and spread `√(np(1-p))` straight from those two numbers, and swap in the normal approximation once `np` and `n(1-p)` both clear `10`.

Blast a signup offer to 200 inboxes, each person clicking or ignoring at the same 3% rate. You will rarely get exactly 6 clicks twice: the count wanders, and its entire spread rides on just two numbers.

14 min
#15

Correlation vs Causation

Average two columns' standardized products into a single number in `[−1, +1]`, test it against Anscombe's quartet to see what one summary hides, then separate cause from reverse cause, a confounder, and coincidence by assigning the treatment at random.

A spreadsheet column of hours slept and a column of exam scores drift up together, and `corr()` hands you one number for the whole pattern, but that number stays silent about which one moved the other.

14 min
#16

Covariance & Correlation Matrices

Pair two columns' deviations into a covariance, stack every pair into one symmetric matrix built in one line as centered data times its own transpose over n − 1, then read the diagonal as each column's spread and the off-diagonal as the cloud's tilt, and divide out the units for the correlation matrix.

Line up two columns of a health survey, height and weight; variance scores them one at a time, but pair their gaps and a single `np.cov(data)` call folds the whole spreadsheet's spread and tilt into one grid of numbers.

16 min
04

Probability

Bayes, conditional probability, and maximum likelihood, reasoning under uncertainty

4/4
#17

Joint & Conditional Probability

Shrink a two-way table of emails to one row or column and read joint, marginal, and conditional probability off the same cells by swapping the denominator, factor any joint two ways with the product rule, test independence by checking whether the conditional equals the marginal, and see why `P(spam | free money)` and `P(free money | spam)` are two different numbers.

Your spam filter flags an email holding `free money` and calls it almost certainly spam. Ask the mirror question, how often spam even contains `free money`, and that number comes back small: the same evidence reads two different ways.

14 min
#18

Bayes' Theorem

Rearrange the product rule into Bayes' theorem, `P(A|B) = P(B|A)·P(A)/P(B)`, read its four pieces (prior, likelihood, posterior, evidence) off a medical-test grid, build the evidence from the law of total probability, watch a rare base rate drag an 80%-accurate positive down to a 7.5% chance of disease, and feed each posterior back as the next prior.

A test catches 80% of a disease, you test positive, and it seems to mean an 80% chance of being sick. The real number, `P(disease | positive)`, can sit near 7.5%, and one line of algebra says why.

16 min
#19

Maximum Likelihood Estimation

Slide a single knob until the data you already collected becomes as probable as it can be, and read that peak as the estimate: a coin's bias is heads over flips, a bell's centre is the sample average. See why likelihood fixes the data and varies the parameter, why the log-likelihood shares the same peak while surviving huge datasets, and why the whole method is Bayes' theorem with the prior deleted.

A coin came up heads `30` times in `100` tosses, but you never watched it get minted. Which bias best explains the flips you actually got, and why is the honest guess simply `30/100`?

18 min
#20

Central Limit Theorem

Average random samples from any lopsided population and pile the averages into a bell centred on the true mean, set its width with `σ/√n` so four times the data only halves it, and separate the three distributions in play so only the sample averages turn normal, never the raw data.

Take a lopsided pile of household incomes, grab `5` at random and average them, then repeat a thousand times. Those averages stack into a clean bell, and each extra draw buys less width than the one before.

12 min
View full 20-topic curriculum