Machine Learning

Machine Learning

Machine Learning lecture notes

A visual, example-led course in machine learning for readers who know probability, statistics and some Python. Every lecture is one interactive page with intuition first, theorems with proofs, real data, Python code with its output, widgets to experiment with, and exercises and project ideas. By the end you can read current ML research papers.

Start reading 23 lectures · 29 pages

Contents

  1. Features, labels, loss and risk; k-nearest neighbours; overfitting and cross-validation; a first look at bias and variance; the Bayes-optimal predictor.

    1. 1.1 What problem are we solving?
    2. 1.2 Loss, risk and empirical risk minimisation
    3. 1.3 A first learner: k-nearest neighbours
    4. 1.4 Overfitting, validation and cross-validation
    5. 1.5 A first look at bias and variance
    6. 1.6 The best anyone could do: the Bayes-optimal predictor
    7. 1.7 Prediction is not explanation
    8. 1.8 Summary, exercises, projects, reading
  2. Vectors and projections, eigenvectors and the SVD, gradients and Hessians, and the optimisers from gradient descent to Adam.

    1. 2.1 Data as vectors
    2. 2.2 Projection: the closest point on a line
    3. 2.3 Matrices are maps
    4. 2.4 Eigenvectors and the spectral theorem
    5. 2.5 The singular value decomposition
    6. 2.6 Calculus in many variables
    7. 2.7 Walking downhill: gradient descent, line search, momentum, Newton and Adam
    8. 2.8 Summary, exercises, projects, reading
  3. Least squares as projection, regression as maximum likelihood, ridge and lasso, Bayesian regression, and why coefficients are not causal effects.

    1. 3.1 Fitting a line
    2. 3.2 Least squares is projection
    3. 3.3 The probabilistic view: noise, likelihood and uncertainty
    4. 3.4 Features and basis expansions
    5. 3.5 Ridge and lasso
    6. 3.6 Bayesian linear regression
    7. 3.7 Coefficients are not causal effects
    8. 3.8 Summary, exercises, projects, reading
  4. The perceptron, logistic and softmax regression, naive Bayes and LDA, and how to evaluate a classifier.

    1. 4.1 Drawing a line between classes
    2. 4.2 The perceptron
    3. 4.3 Logistic regression
    4. 4.4 More than two classes: softmax regression
    5. 4.5 Generative classifiers: discriminant analysis and naive Bayes
    6. 4.6 Evaluating a classifier
    7. 4.7 Propensity scores: classification for causal inference
    8. 4.8 Summary, exercises, projects, reading
  5. What a loss encodes, surrogates and proper scoring rules, and the bias–variance decomposition computed exactly.

    1. 5.1 What a loss encodes
    2. 5.2 Regression losses and what they estimate
    3. 5.3 Losses from likelihoods
    4. 5.4 Classification: the 0–1 loss and its surrogates
    5. 5.5 Scoring probabilities: proper scoring rules
    6. 5.6 Bias and variance, precisely
    7. 5.7 Approximation, estimation, and choosing complexity
    8. 5.8 Losses you will meet later
    9. 5.9 Summary, exercises, projects, reading
  6. Why training performance can predict test performance: PAC learning, VC dimension, Rademacher complexity and double descent.

    1. 6.1 The puzzle: why should training error mean anything?
    2. 6.2 One classifier: Hoeffding's inequality
    3. 6.3 PAC learning and finite classes
    4. 6.4 No free lunch
    5. 6.5 Infinite classes: shattering and VC dimension
    6. 6.6 Rademacher complexity: fitting pure noise
    7. 6.7 Linear classes, margins and Lipschitz losses
    8. 6.8 Modern puzzles: double descent, benign overfitting, PAC-Bayes
    9. 6.9 Summary, exercises, projects, reading
  7. Margins, duality and the SVM, the kernel trick, kernel ridge regression and Gaussian processes.

    1. 7.1 The widest street
    2. 7.2 Constrained optimisation: Lagrange multipliers, duality and KKT
    3. 7.3 The dual SVM, support vectors and soft margins
    4. 7.4 Feature maps and the kernel trick
    5. 7.5 Which functions are kernels?
    6. 7.6 The representer theorem and kernel ridge regression
    7. 7.7 Gaussian processes
    8. 7.8 Kernels at scale, in deep learning and on quantum computers
    9. 7.9 Summary, exercises, projects, reading
  8. Decision trees, bagging and random forests, AdaBoost, gradient boosting and XGBoost, SHAP, and causal forests.

    1. 8.1 Trees as graphs
    2. 8.2 Growing a tree: impurity, greedy splits, pruning
    3. 8.3 Why one tree is not enough
    4. 8.4 Bagging and random forests
    5. 8.5 Boosting I: AdaBoost
    6. 8.6 Boosting II: gradient boosting
    7. 8.7 XGBoost and its relatives
    8. 8.8 Why trees still win on tables
    9. 8.9 Opening the black box: Shapley values and SHAP
    10. 8.10 Bayesian trees and causal forests
    11. 8.11 Summary, exercises, projects, reading
  9. Graphs between data points: the graph Laplacian, label propagation, PageRank and graph neural networks.

    1. 9.1 Encoding graphs
    2. 9.2 From data to graphs
    3. 9.3 The graph Laplacian and smoothness
    4. 9.4 Spectra of graphs: what the eigenvectors look like
    5. 9.5 Semi-supervised learning: harmonic functions and label propagation
    6. 9.6 Random walks, diffusion and PageRank
    7. 9.7 Graph neural networks: learnable propagation
    8. 9.8 Graph-level tasks and the limits of message passing
    9. 9.9 Summary, exercises, projects, reading
  10. Shallow and deep ReLU networks as piecewise-linear functions, activation functions, depth and universal approximation.

    1. 10a.1 Shallow networks
    2. 10a.2 Linear regions
    3. 10a.3 Activation functions
    4. 10a.4 Composing networks: folding, clipping and depth
    5. 10a.5 Universal approximation, and what depth buys
    6. 10a.6 Summary, exercises, projects, reading
  11. Backpropagation by hand and by autodiff, initialisation, optimisers and regularisation for networks.

    1. 10b.1 Backpropagation by hand
    2. 10b.2 Backpropagation for networks, and automatic differentiation
    3. 10b.3 Initialisation: keeping the signal alive
    4. 10b.4 Training in practice: optimisers and schedules
    5. 10b.5 Regularisation
    6. 10b.6 Knowing what you don't know
    7. 10b.7 Summary, exercises, projects, reading
  12. Shattered gradients, residual connections and normalisation, convolutional networks, and recurrent networks with LSTMs.

    1. 11.1 Why depth is hard: shattered gradients
    2. 11.2 Residual connections
    3. 11.3 Normalisation
    4. 11.4 Convolution: a sliding pattern detector
    5. 11.5 Pooling, invariance and receptive fields
    6. 11.6 Convolutional networks in practice
    7. 11.7 Recurrent networks and the gradient through time
    8. 11.8 LSTMs at work: forecasting and writing
    9. 11.9 The limits of recurrence, and its return
    10. 11.10 Summary, exercises, projects, reading
  13. Embeddings, self-attention, the transformer block, tokenisation, decoding strategies and retrieval-augmented generation.

    1. 12.1 Representing words
    2. 12.2 Encoders, decoders and the bottleneck
    3. 12.3 Attention: soft dictionary lookup
    4. 12.4 Multi-head attention and positions
    5. 12.5 The transformer
    6. 12.6 BERT, GPT and a tiny GPT of our own
    7. 12.7 Tokenisation: byte-pair encoding
    8. 12.8 Decoding: from probabilities to text
    9. 12.9 Pre-training, in-context learning and scale
    10. 12.10 Transformers in systems: retrieval and RAG
    11. 12.11 Summary, exercises, projects, reading
  14. Sentiment classifiers, bias in word embeddings, fairness criteria and the impossibility theorems, and a real audit.

    1. 13.1 Sentiment as classification
    2. 13.2 Lexicons, learned models and domain shift
    3. 13.3 Pre-trained representations
    4. 13.4 Bias in word embeddings
    5. 13.5 From representations to decisions
    6. 13.6 Fairness criteria
    7. 13.7 The impossibility theorems
    8. 13.8 Auditing the Lecture 8 income model
    9. 13.9 Causal notions of fairness
    10. 13.10 Summary, exercises, projects, reading
  15. Density estimation, the curse of dimensionality, anomaly detection, Hopfield networks and self-supervised learning.

    1. 14.1 What "structure" means
    2. 14.2 Histograms and kernel density estimation
    3. 14.3 The curse of dimensionality
    4. 14.4 Anomaly detection
    5. 14.5 Energy-based models: Hopfield networks and Boltzmann machines
    6. 14.6 Self-supervised learning: inventing labels from the data
    7. 14.7 Evaluating without ground truth
    8. 14.8 Summary, exercises, projects, reading
  16. Lecture 15Clustering

    k-means and k-means++, choosing k, hierarchical and density-based clustering, spectral clustering, and Kleinberg's impossibility theorem.

    1. 15.1 k-means
    2. 15.2 Choosing k
    3. 15.3 Hierarchical clustering and dendrograms
    4. 15.4 Density-based clustering: DBSCAN and HDBSCAN
    5. 15.5 Spectral clustering
    6. 15.6 Is clustering well defined?
    7. 15.7 Summary, exercises, projects, reading
  17. PCA and the SVD, eigenfaces, probabilistic PCA, random projections and matrix factorisation for recommendations.

    1. 16a.1 Principal component analysis
    2. 16a.2 Choosing the dimension, and PCA of genomes
    3. 16a.3 Probabilistic PCA and factor analysis
    4. 16a.4 Random projections and the Johnson–Lindenstrauss lemma
    5. 16a.5 Matrix factorisation for recommendations
    6. 16a.6 Summary, exercises, projects, reading
  18. MDS, Isomap, Laplacian eigenmaps, t-SNE and UMAP, and autoencoders and VAEs.

    1. 16b.1 Multidimensional scaling, Isomap and Laplacian eigenmaps
    2. 16b.2 t-SNE and UMAP: what they preserve and how they mislead
    3. 16b.3 A single-cell pipeline: PCA, a graph, clusters, UMAP
    4. 16b.4 Autoencoders and variational autoencoders
    5. 16b.5 Summary, exercises, projects, reading
  19. Gaussian mixtures and the EM algorithm, the ELBO, Dirichlet processes, hidden Markov models and topic models.

    1. 17a.1 Gaussian mixtures
    2. 17a.2 The EM algorithm
    3. 17a.3 Why EM works
    4. 17a.4 How many components? BIC and label switching
    5. 17a.5 Bayesian mixtures and the Dirichlet process
    6. 17a.6 Mixtures in time: hidden Markov models
    7. 17a.7 Mixtures of words: topic models
    8. 17a.8 Variational inference, and the VAE revisited
    9. 17a.9 Summary, exercises, projects, reading
  20. Sklar's theorem, rank correlations and tail dependence, copula families, synthetic tabular data and the nonparanormal.

    1. 17b.1 Dependence beyond correlation
    2. 17b.2 Sklar's theorem: separating margins from dependence
    3. 17b.3 Measuring dependence with copulas: ranks and tails
    4. 17b.4 Copula families, fitting, and joint crashes
    5. 17b.5 Copulas in machine learning I: synthetic tabular data
    6. 17b.6 Copulas in machine learning II: the nonparanormal
    7. 17b.7 Summary, exercises, projects, reading
  21. The DFT and FFT, sampling and aliasing, filtering, spectral estimation, spectrograms, wavelets and matched filtering.

    1. 18.1 Sinusoids and roots of unity
    2. 18.2 The discrete Fourier transform and the FFT
    3. 18.3 Sampling and aliasing
    4. 18.4 Convolution and filtering
    5. 18.5 Spectral estimation: periodograms, Welch and windows
    6. 18.6 Time and frequency together: spectrograms and uncertainty
    7. 18.7 Wavelets
    8. 18.8 Matched filtering and the first gravitational wave
    9. 18.9 Summary, exercises, projects, reading
  22. CNNs and symmetry, transfer learning and CLIP, diffusion as denoising, and learning from spectrograms.

    1. 19.1 Images as tensors; hand-designed features
    2. 19.2 CNNs through the Fourier lens; augmentation as symmetry
    3. 19.3 Transfer learning
    4. 19.4 Vision transformers, CLIP and zero-shot classification
    5. 19.5 Generative image models: diffusion as denoising
    6. 19.6 Sound: spectrograms, the mel scale and MFCCs
    7. 19.7 Audio classification
    8. 19.8 Speech recognition at scale
    9. 19.9 Summary, exercises, projects, reading
  23. Correlation networks, graphs from smooth signals, Gaussian graphical models and the graphical lasso.

    1. 20a.1 Correlation networks and their pitfalls
    2. 20a.2 Learning a graph from smooth signals
    3. 20a.3 Gaussian graphical models: zeros in the precision matrix
    4. 20a.4 The graphical lasso and neighbourhood selection
    5. 20a.5 Summary, exercises, projects, reading
  24. DAGs and d-separation, Markov equivalence, the PC algorithm, GES, NOTEARS and interventions.

    1. 20b.1 DAGs, d-separation and Markov equivalence
    2. 20b.2 Constraint-based discovery: the PC algorithm
    3. 20b.3 Score-based discovery: BIC and greedy equivalence search
    4. 20b.4 Continuous optimisation: NOTEARS, and its pitfalls
    5. 20b.5 Interventions and identifiability
    6. 20b.6 Summary, exercises, projects, reading
  25. The agent–environment loop, bandits and regret, off-policy evaluation, MDPs, Bellman equations and dynamic programming.

    1. 21a.1 The agent–environment loop
    2. 21a.2 Multi-armed bandits
    3. 21a.3 Markov decision processes and value functions
    4. 21a.4 Bellman equations and dynamic programming
    5. 21a.5 Summary, exercises, projects, reading
  26. Monte Carlo and TD learning, n-step returns, SARSA and Q-learning, the deadly triad and DQN.

    1. 21b.1 Learning values from experience: Monte Carlo and TD
    2. 21b.2 Control: SARSA, Q-learning and Expected SARSA
    3. 21b.3 Function approximation and the deadly triad
    4. 21b.4 Deep Q-networks
    5. 21b.5 Summary, exercises, projects, reading
  27. The policy gradient theorem, actor–critic and GAE, TRPO and PPO, Soft Actor-Critic, MCTS and offline RL.

    1. 22a.1 Why optimise policies directly
    2. 22a.2 The policy gradient theorem, REINFORCE and baselines
    3. 22a.3 Actor–critic and generalised advantage estimation
    4. 22a.4 Trust regions: TRPO and PPO
    5. 22a.5 Maximum-entropy RL and Soft Actor-Critic
    6. 22a.6 Planning with search and models
    7. 22a.7 Offline RL and off-policy evaluation
    8. 22a.8 Summary, exercises, projects, reading
  28. Reward models from preferences, RLHF and DPO, GRPO and verifiable rewards, and reward hacking.

    1. 22b.1 From pretrained model to assistant; reward models from preferences
    2. 22b.2 RLHF, the KL-regularised optimum and DPO
    3. 22b.3 RL with verifiable rewards: GRPO and reasoning models
    4. 22b.4 Reward hacking and Goodhart's law
    5. 22b.5 Summary, exercises, projects, reading
  29. The anatomy of an ML paper, a notation decoder, reading experiments critically, and guided dissections of three papers.

    1. 23.1 The anatomy of an ML paper
    2. 23.2 A notation decoder
    3. 23.3 Reading experiments critically
    4. 23.4 Three guided dissections
    5. 23.5 Reproducing a figure: grokking
    6. 23.6 The 2026 map, and a map of the course
    7. 23.7 Exercises, projects, reading