Key Moments

Stanford CS229 Machine Learning | Spring 2026 | Lecture 2: Supervised Learning Setup

Stanford OnlineStanford Online
Education5 min read79 min video
Jul 29, 2026|30,116 views|452|23
Save to Pod
TL;DR

Stanford's CS229 lecture introduces supervised learning and linear regression, highlighting that even simple algorithms like stochastic gradient descent, when scaled with massive datasets and compute, form the bedrock of modern AI, despite the potential for computational tradeoffs.

Key Insights

1

Supervised learning relies on a hypothesis function mapping from an abstract set X to an abstract set Y, which aims to generalize to unseen data.

2

Linear regression, a classic yet powerful technique, uses linear/affine hypothesis functions (h(x) = θ₀ + θ₁x) to model relationships, parameterized by 'theta' coefficients.

3

The core objective in supervised learning is to minimize a loss function (like mean squared error in Ordinary Least Squares) to find the best 'theta' parameters.

4

Stochastic Gradient Descent (SGD) is a fundamental optimization algorithm used in machine learning, which iteratively updates model parameters using small batches of data, offering computational advantages over using the entire dataset.

5

Model size and computational power (e.g., GPUs) have been revolutionary, enabling larger models and driving AI advancements, often prioritizing scale and compute over extreme parameter precision.

6

The choice of batch size in training is a complex interplay between computational efficiency, algorithmic convergence, and generalization performance, with larger batches often favored in modern deep learning for system utilization.

The core concept of supervised learning setup

The lecture kicks off by defining supervised learning as a process where a machine is explicitly taught to perform a task, such as classifying an image as a cat or a dog. The instructor emphasizes a highly abstract and mathematical approach to ensure clarity and communication. Key to this is the 'hypothesis function,' denoted as 'h,' which maps from an input set X to an output set Y. The goal is to train this function on a dataset so it can generalize to new, unseen data. The distinction between regression (where Y is continuous, like a price) and classification (where Y is discrete, like a label) is introduced, with linear regression serving as the first concrete example.

Linear regression: a simple yet powerful hypothesis class

Linear regression is presented as a foundational algorithm, predating modern machine learning but remaining highly relevant. The hypothesis function for linear regression is a linear (or affine) function, typically represented as h(x) = θ₀ + θ₁x. Here, θ₀ and θ₁ are parameters, or 'weights,' that the model learns. The lecture introduces a convention where an extra feature, x₀, is added and set to 1, allowing the function to be written more compactly in vector form: h(x) = θᵀx. This parametrization significantly reduces the search space of possible functions, making the problem tractable. The geometric interpretation of this is fitting a line (or a hyperplane in higher dimensions) to the data points. The instructor highlights that although seemingly simple, linear models form the backbone of many complex machine learning systems.

Minimizing error with Ordinary Least Squares (OLS)

The central task in training a linear model is to find the optimal parameters (θ) that best fit the training data. This is achieved by minimizing an error or loss function. The lecture introduces the concept of Empirical Risk Minimization (ERM) and focuses on the Mean Squared Error (MSE) as the loss function for linear regression. This leads to the Ordinary Least Squares (OLS) method, where the goal is to find the θ that minimizes the sum of the squared differences between the predicted values (h(xᵢ)) and the actual target values (yᵢ) for all training examples. The mathematical derivation involves calculus, specifically finding the point where the gradient of the loss function with respect to θ is zero. This leads to the 'normal equations,' a closed-form solution for θ: θ = (XᵀX)⁻¹Xᵀy, assuming XᵀX is invertible. The lecture stresses the importance of understanding vector and matrix calculus for these derivations, offering Friday sessions for review.

Stochastic Gradient Descent (SGD) for large-scale optimization

While OLS provides a direct solution, it becomes computationally prohibitive for massive datasets due to the matrix inversion (XᵀX)⁻¹. This is where iterative optimization algorithms like Gradient Descent come in. The lecture introduces Stochastic Gradient Descent (SGD) as a highly scalable and practical approach. Instead of calculating the gradient of the loss function using the entire dataset (Batch Gradient Descent), SGD updates the parameters using a small random subset of the data, known as a 'mini-batch.' This significantly reduces computational cost per update, allowing models to train on vastly larger datasets. The instructor notes that while these algorithms might seem 'dumb' due to their simplicity, their scalability on massive datasets has been key to modern AI breakthroughs. Practical considerations like choosing an appropriate step size (learning rate) and the potential for oscillations are discussed.

The role of model size and computational scale

A significant point made is that a major revolution in machine learning has been driven by simply making models larger – increasing the number of parameters and training them on more data using powerful hardware like GPUs. This approach, often associated with deep learning, prioritizes scale and computational throughput. The lecture suggests that modern AI often benefits more from larger models and more data than from achieving extremely precise parameter estimation. This shift in focus means that aspects like computational efficiency and GPU utilization become critical factors in model development, sometimes even overriding purely statistical optimality concerns. The concept of 'model capacity' and how larger models can potentially capture more complex patterns is implied.

Generalization: the essence of machine learning

The ultimate goal of any machine learning model is to generalize well to unseen data. The training process aims to find a hypothesis function that not only fits the training data but also makes accurate predictions on new examples. The lecture emphasizes that this ability to generalize is the core of machine learning. While simple models like linear regression might generalize well due to their inherent simplicity, the trend towards larger, more complex models raises questions about how they achieve generalization. The lecture frames the entire endeavor as a leap of faith: believing that a model that performs well on the training data will also perform well in the real world, a cornerstone assumption in statistical inference and machine learning.

Mathematical notation and resources

The course adopts a rigorous mathematical approach, utilizing vector and matrix notation extensively. Concepts like vectors, matrices, derivatives, partial derivatives, and matrix inversion are fundamental. The instructor repeatedly advises students to leverage supplementary resources, particularly the Friday TA sessions, to solidify their understanding of this mathematical machinery. Common conventions, such as assuming x₀=1 and the use of 'n' for the number of examples and 'd' for dimensions, are established. The lecture concludes by reiterating the importance of mastering this notation for further topics, including classification loss functions and advanced optimization techniques like backpropagation.

Supervised Learning Setup: Key Takeaways

Practical takeaways from this episode

Do This

Visualize your data to identify patterns.
Understand the difference between regression (continuous y) and classification (discrete y).
Leverage supplementary resources like Friday TA sessions for clarification.
Ensure your training data is representative of the real world.
When using SGD, choose random mini-batches that reflect the overall data distribution.

Avoid This

Do not hesitate to ask questions during lectures.
Do not solely rely on handwritten notes; refer to Tino's official course notes.
Do not ignore the importance of computational limits and system efficiency (e.g., GPU utilization).
Do not assume that better performance on the training set guarantees better performance on the test set.
Do not be afraid to experiment with hyperparameters like learning rate and batch size.

Common Questions

Supervised learning involves explicitly telling a machine what you want it to classify or predict. This is done by providing the machine with labeled data, where each input (X) is paired with its correct output (Y). The goal is for the machine to learn a function that can generalize to new, unseen data.

Topics

Mentioned in this video

More from Stanford Online

View all 150 summaries

Ask anything from this episode.

Save it, chat with it, and connect it to Claude or ChatGPT. Get cited answers from the actual content — and build your own knowledge base of every podcast and video you care about.

Get Started Free