Skip to content
Series
18 posts

Reading Berkeley CS189 Introduction to Machine Learning

A lecture-by-lecture, homework-by-homework reading of the public materials of Berkeley CS189 (Introduction to Machine Learning), with the term stated in every post, filling in the fuller mathematical foundations of ML after CS188.

Spring 2025 Overview: HW1–7 with Code and Data You Can Run, Plus What Fall 2026 Looks Like | Berkeley CS189 Course Overview

CS189 exists online in several terms. From post 2 onward this series uses Spring 2026 (eecs189.org/sp26, A3) as its base, walking through each lecture block and assignment; Spring 2025 (Shewchuk) is a different classic route with 25 lectures of notes, HW1–7 and past exams, but its official recordings sit behind a bCourses login; Fall 2026 is still in progress and serves only as a reference. This post is the series entry point and full table of contents.

Three Versions of CS189: Spring 2026 as the Base, Spring 2025 as the Classic, Fall 2026 in Progress | Berkeley CS189 Course Map

Several semesters of Berkeley CS189 are online at once. From here on, this series follows Spring 2026 (Listgarten/Dimakis): its slides, 25 lecture videos, discussions with solutions, HW1–5 handouts and midterm solutions are all publicly accessible, so it rates A3. Spring 2025 (Shewchuk) is a different, classic route and the only one that covers SVMs, decision trees, PCA and boosting. Fall 2025's homework folders open empty to outside readers, so it was not chosen. Fall 2026 is still running and serves only as a comparison.

ML Problem Framing, Data Tools, Terminology and Techniques | Berkeley CS189 Lectures 1–3

The first three lectures of CS189 Spring 2026 hold off on derivations. They teach you how to tell whether a problem calls for ML, how to look at data with pandas and Plotly, and how to run one full train/validate/test cycle in scikit-learn. Lecture 1 has slides but no recording; Lectures 2–3 have slides and video; Discussion 1 is a calculus, linear algebra and probability warm-up with solutions and a walkthrough. Together they set you up directly for HW1.

K-means, Probability Review, MLE, Multivariate Gaussians and GMMs | Berkeley CS189 Lectures 4–7

Lectures 4–7 of CS189 Spring 2026 tie unsupervised learning into one thread. K-means clusters the data, then its weaknesses show up: hard assignments, no probabilistic framing, and a bias toward round clusters of similar size. The course reviews probability, introduces maximum likelihood estimation (MLE) and multivariate Gaussians, and rewrites K-means as a Gaussian mixture model (GMM). The GMM log-likelihood has no closed-form solution, and that gap leads the course to gradient descent. All four lectures have slides and video; Discussions 2–3 come with solutions and walkthroughs.

Linear Regression, the Geometry of Least Squares, and Regularization | Berkeley CS189 Lectures 7–10

Over four lectures, CS189 Spring 2026 presents linear regression from three angles that meet in one formula: MLE under Gaussian noise is least squares; the least-squares solution is the orthogonal projection of y onto the column space of X; and when features are collinear or too many, ridge (the MAP estimate under a Gaussian prior) or lasso (a Laplace prior) pulls the solution back, with λ chosen on a validation set. Slides, videos, and Discussion 3–4 solutions are all publicly accessible.

Linear Algebra / Calculus / Probability Warm-up + Fashion Coding | Berkeley CS189 Assignment 1

CS189 Spring 2026 HW1 has three pieces: ten written math warm-ups (a linear system, limits of matrix powers via eigendecomposition, SVD, a matrix that flips an image, partial derivatives, a chain rule over a recursion, and four probability problems including Bayes for cancer screening), plus two public Modal notebooks on Fashion-MNIST. Part 1 drills pandas / Plotly / K-means / an MLP / matrix-based image augmentation / tensor puzzles; Part 2 does price regression, MAE / MSE / R², confusion matrices, and finally a secret test set whose images have been rotated. Due Feb 20; no official solutions.

Classification, Generative Classifiers, Logistic Regression, and ROC | Berkeley CS189 Lectures 11–12

CS189 Spring 2026 Lec 11–12 splits classification into two routes. Generative models fit p(x|y) for each class (GDA: shared covariance gives LDA and a linear boundary, per-class covariance gives QDA and a quadratic one). Discriminative models fit p(y|x) directly (logistic regression: sigmoid, softmax, cross-entropy MLE, no closed form, so gradient descent). The bridge: the LDA posterior can always be written in logistic form, but not the other way around. For evaluation, accuracy misleads under class imbalance; ROC/AUC sweeps every threshold and ignores calibration; PR curves care about class balance.

& 15: Convergence, Momentum, Adam, SGD | Berkeley CS189 Lecture 13

CS189 Spring 2026 covers gradient descent in two lectures. Lec 13 derives the learning-rate limit and the condition number from the Hessian's eigenvalues, then moves through momentum, learning-rate schedules, AdaGrad/RMSProp/Adam, and mini-batch SGD. In Lec 15, Dimakis walks through the same material again, starting from a gradient computed by hand on a small data table. Both slide decks, the recordings, Lec 13's handwritten notes, and Discussions 6 and 7 (with solutions) are all publicly accessible.

& 16: MLE vs MAP, Bias-Variance, Entropy and KL, Plus a Midterm Self-Check | Berkeley CS189 Lecture 14

Lec 14 recasts ridge as MAP under least squares plus a Gaussian prior, breaks down bias-variance, and closes by using Chatbot Arena to show how to read a paper. Lec 16 builds entropy from compression, moves on to KL and cross-entropy, and lands back on the logistic regression loss. The 3/17 midterm and its official solutions are public in the past-exams folder, with 6 problems, 56 points, 110 minutes, and 6 problem-by-problem walkthrough videos, so you can sit it as a mock exam.

Chatbot Arena Paper Questions, Regression, MLE/MAP, From GMMs to Flow Matching | Berkeley CS189 Assignment 2

HW2 is a written-only assignment with 10 problems. The first half practices reading a paper (Chatbot Arena) and the core derivations for regression and MLE/MAP. The two heaviest problems come last: Mixed Feelings goes from k-means' fragility to outliers through robust k-means to a GMM with a uniform background, and Watch Me Flow Dat proves that conditional flow matching and a discretized MLE are the same objective. The problem PDF and LaTeX template are freely downloadable; there are no official solutions.

Depth, Universal Approximation, Activations, and Backpropagation | Berkeley CS189 Lectures 17–18

Lec 17 uses XOR to show that a linear model, and even a stack of linear layers, cannot learn a nonlinear boundary, while one ReLU layer can. The universal approximation theorem guarantees that a network exists but not how to find its weights or how wide it must be. Lec 18 turns the chain rule into backpropagation on a computation graph: gradients from multiple paths add up, and the cost is linear in the number of parameters, versus quadratic for finite differences. Discussion 8 has you prove a GD convergence rate and 1-D ReLU universal approximation yourself.

Autograd from Scratch (BearTensor), Newton's Method, and the Information Bottleneck | Berkeley CS189 Assignment 3

HW3 has two halves. The four written problems run from Newton's method for logistic regression and a convergence analysis of coordinate descent, through backprop, VJPs, and implicit differentiation, to an information-bottleneck view of what deep networks compress. The notebook has you build a BearTensor computation graph in NumPy, topological-sort backprop, and SGD/Momentum/Adam, then train a red-wine quality regressor with it, plus an optional Muon optimizer. Problems and notebook are public; official solutions and hidden tests are not.

Initialization, BatchNorm, CNNs, Early Stopping, and Double Descent | Berkeley CS189 Lectures 19–20

Lec 19 wraps up backprop, then tackles how to keep gradients flowing: all-zero initialization makes every unit learn the same thing, so use small random values (He init for ReLU), and batch norm normalizes pre-activations with mini-batch means and variances. The second half introduces CNNs: local connectivity plus weight sharing lets one feature detector scan the whole image. Lec 20 finishes pooling, receptive fields, and CNN training, then covers early stopping, dropout, and double descent, which breaks the classic bias-variance picture.

Transformers | Berkeley CS189 Lectures 21–22

Lec 21 starts with what CNNs lack: only the top layers see the whole image. It then builds up through TF-IDF, RNN image captioning, and soft attention. Lec 22 derives self-attention from a "soft dictionary lookup": three linear layers produce Q, K, and V, the output is SoftMax(QKᵀ/√D)V, and multiple heads, an MLP, residual connections, and LayerNorm turn it into a transformer layer. Attention itself ignores order, so you need positional encodings. Discussion 10 has you compute QKV by hand and prove why the scores are divided by √D.

ResNet/Transformer Paper Questions and Implementing CNN, ResNet, Transformer, DNABERT, and ConvNeXt | Berkeley CS189 Assignment 4

HW4 has three pieces. The written part has you read ResNet and Attention Is All You Need in the order problem → existing work → proposal → method → contribution. The 4.1 notebook builds a CNN and ResNet-18 in PyTorch, then assembles an encoder-decoder transformer step by step from softmax, trains it on TinyStories, and generates stories. The 4.2 notebook cuts DNA into 6-mers for a pretrained DNABERT to classify species, and turns audio into spectrograms for ConvNeXt, comparing training from scratch, a frozen backbone, and full unfreezing. Two Kaggle competitions; due 5/1. Outside readers get the problems but not the course data bundle or tests.

LLM Training and Applications, Self-Supervised Learning | Berkeley CS189 Lectures 23–24

Lec 23 wires a transformer into a next-token predictor: tokenize, look up embeddings, stack L layers of masked attention, multiply back by the embedding table and apply softmax, and train with cross-entropy (that is, MLE). Pretraining supplies knowledge; to chat, a model also needs SFT, LoRA, RLHF, or DPO, and at inference time it leans on in-context learning, RAG, chain-of-thought, and tool calls. Lec 24 generalizes "invent a fake supervised task" to images: autoencoders, colorization, inpainting, rotation, jigsaw puzzles, clustering, and finally contrastive learning, SimCLR, and CLIP. Discussion 11 practices positional encodings, RoPE, causal masks, and the KV cache.

AI for Protein Engineering, Agents and Environments, and Where to Go Next | Berkeley CS189 Lectures 25–27

The last three lectures take the semester's tools to two frontiers. Lec 25 is about proteins: AlphaFold2 cracked sequence-to-structure, but the real engineering bottleneck is predicting which sequence has the function you want, and design means acting as your own model's adversary in a discrete space of size 20^L. The slides reduce conditional generation p(x|y) to three statistically correct routes, all of which come back to Bayes' rule. Lec 26 was an online guest lecture with no public materials. Lec 27 defines an agent (an LLM in a loop, using tools, deciding its next step) and argues that data is being replaced by environments: Docker + task + verifier, used for SFT, RL (RLVR, GRPO), or weight-free GEPA. For final-exam practice, use the Fall 2025 and Spring 2025 finals with solutions; the Spring 2026 final is not published.

(Optional) Guide: InfoNCE for Biology, Diffusion Theory, LLM Fine-Tuning + Kaggle | Berkeley CS189 Assignment 5

HW5 is the only Spring 2026 assignment marked optional, due 5/11, the same day as the final. The written part has three pieces: derive InfoNCE gradients and the trade-off in the number of negatives, using scRNA-seq as the setting; prove the optimal denoiser is a conditional expectation and derive the continuity equation; generalize flow matching's straight-line path to arbitrary interpolations. The notebook is a full LLM fine-tuning pipeline: Qwen2.5-0.5B-Instruct is fixed, MMLU machine_learning is converted to chat format, TRL's SFTTrainer does full fine-tuning, accuracy on CS189 exam questions is compared before and after, and predictions on a 169-question test set go to Kaggle, all while guarding against catastrophic forgetting. An official hw5-sol.pdf is provided, covering the written part only.