Marginal

Machine Learning

The foundations of modern machine learning: supervised learning and loss functions, logistic and softmax regression, gradient descent, stochastic gradients, momentum and Adam, convexity and convergence rates, train–validation–test splits, bias and variance, regularization and weight decay, hyperparameters, kernels, Gaussian processes and generalization bounds.

29 lessons in 4 units

Start your free trial14 days free. No card needed.
What you'll learn

29 lessons, one small step at a time

Each lesson states its goal, then works up to it in short steps with practice after each. A placement test at the start skips what you already know.

Supervised Learning

8 lessons
  1. Regression lossesCompute squared and absolute error, and tell which constant prediction each loss rewards.
  2. Supervised learning & lossesSet up a supervised learning problem, and compute the cross-entropy and the accuracy of a classifier.
  3. The sigmoid functionCompute the sigmoid of a score, its inverse the logit, and its slope.
  4. Logistic predictionsCompute a logistic regression's predicted probabilities, find its decision boundary, read its weights as odds ratios, and score its predictions with log loss.
  5. Precision, recall & ROCCompute precision, recall and F1 from a confusion matrix, and the share of flagged cases that are truly positive at a given base rate.
  6. Logistic regression gradientsCompute the gradient of the logistic loss, explain why the loss is convex, and take a gradient step.
  7. The softmax functionCompute softmax probabilities from logits, shift the logits for stable computation, and reshape the distribution with temperature.
  8. Softmax classificationCompute the cross-entropy loss of a softmax classifier, its gradient with respect to the logits, and a training step for multiclass logistic regression.

Optimization

8 lessons
  1. A gradient stepTake a gradient-descent step in one dimension and in many, and explain why a small enough step always lowers the loss.
  2. Gradient descent dynamicsCompute how gradient descent shrinks the error along each direction of a quadratic loss, and the learning rate above which it diverges.
  3. Minibatches & epochsConvert between examples, batches, steps, epochs and tokens, and compute a minibatch gradient estimate.
  4. Stochastic gradient descentCompute how the noise of a minibatch gradient depends on the batch size, and use it to choose a batch size.
  5. MomentumCompute momentum's velocity over a few steps, and its steady-state speedup over plain gradient descent.
  6. AdamCompute Adam's bias-corrected first and second moments and the step they produce, and tell AdamW from L2 regularization.
  7. Convex functionsTell convex functions from non-convex ones, and find the smoothness and strong-convexity constants of a quadratic loss.
  8. Convergence ratesCompute gradient descent's per-step progress on a convex loss and the number of steps it needs, from the condition number.

Generalization

9 lessons
  1. Train, validation & test setsAssign each task to the training, validation or test set, and count the models and examples of cross-validation.
  2. Computing bias & varianceCompute the bias and the variance of a model's predictions across retrained models, and the expected squared error they add up to.
  3. Bias, variance & overfittingDecompose expected error into bias, variance and noise, diagnose underfitting and overfitting, and read learning curves.
  4. Decision trees & ensemblesCompute the Gini impurity of a node and the impurity reduction of a split, and explain how pruning and ensembles fight overfitting.
  5. Regularization & weight decayCompute a weight-decay step, name the other regularizers, and choose the regularization strength on validation data.
  6. HyperparametersCount the training runs a hyperparameter search needs, and choose hyperparameters without leaking the test set.
  7. L1 & sparsityApply an L1 soft-thresholding step, and contrast L1 with L2 regularization.
  8. Hoeffding's inequalityBound the gap between a fixed classifier's training error and its true error with Hoeffding's inequality, and find how much data a target accuracy needs.
  9. Generalization boundsCompute the sample size a finite class of classifiers needs, and the generalization gap a given sample guarantees.

Kernels & Gaussian Processes

4 lessons
  1. Kernel functionsCompute RBF and polynomial kernel values, and check whether a proposed kernel gives a positive semidefinite Gram matrix.
  2. Kernel ridge regressionCompute kernel ridge regression predictions from one and from several training points, and explain where the formula comes from.
  3. Gaussian process priorsCompute correlations between function values under a Gaussian process prior, draw a function from it, and relate the kernel to smoothness.
  4. Gaussian process regressionCompute a Gaussian process's posterior mean and variance after one observation.
Sample lesson

Regression losses

Goal: Compute squared and absolute error, and tell which constant prediction each loss rewards.

In supervised learning a model maps inputs to predictions, and training chooses its parameters to minimize the average loss on labeled examples. The loss encodes what counts as a good prediction, and choosing it is one of the most consequential modeling decisions.

We will compute squared and absolute error and finish with what each loss rewards.

Step 1: Squared and absolute error

For a prediction ŷ of a numeric target y, the squared error is (ŷ − y)², and the mean squared error (MSE) averages it over examples. Squaring makes large mistakes count far more than small ones: halving every error divides the MSE by 4, and one error of 4 costs as much as sixteen errors of 1. The absolute error |ŷ − y| grows only linearly, so the mean absolute error (MAE) is less dominated by a few large mistakes. Two models with errors (1, 1, 1, 1) and (0, 0, 0, 4) have the same MAE, 1, but MSEs of 1 and 4.

Step 2: What each loss rewards

The difference shows clearly in the simplest model, a single constant prediction c for every example. The MSE is minimized by the mean of the targets, the MAE by the median. For targets (1, 1, 4, 6, 35), the mean is 9.4, pulled up by the outlier 35, while the median is 4. So squared error chases outliers, and one huge outlier can drag the fit far from most of the data; absolute error is robust to them. Choosing a loss is choosing which kind of typical value the model aims for.

In the app, each step ends with practice questions, new ones every time, and the lesson comes back later in spaced reviews.

Start Machine Learning

Lessons that need something you haven't learned yet bring it in first, from any course.

Start your free trial14 days free. No card needed.