Module 2: Linear Regression and Gradient Descent

This module introduces learning by optimization in the context of the linear regression model. You will examine how the model fits a function to data by minimizing a loss function and how gradient descent serves as a key algorithm for updating parameters.

Learning Objectives

  • Define models, loss functions, and parameters in linear regression.
  • Describe learning by optimization and the purpose of gradient descent.
  • Apply gradient descent to minimize loss in linear regression.
  • Derive the update rule for gradient descent.
  • Compare batch, stochastic, and mini-batch gradient descent methods.
  • Evaluate how the learning rate and the loss shape affect convergence.
0 of 8 stages complete
1 · Watch

The module in two minutes

An animated overview of the module’s through-line. Watch it before the lecture — it is the map, not the territory.

Lecture shorts

Short lectures and code walkthroughs from the instructor that reinforce this module. Some open partway into a longer video — that chapter is the part matched to this module.

Optimization — nonlinearity, gradient descent, landscapes, saddle points (5:33)
2 · Listen

Orientation audio

Loss, gradients, and the training loop the whole course reuses — a spoken orientation before you start.

3 · Read & play

The through-line

Module 1 said a model is a function with free parameters. This module answers the obvious next question: chosen how? For linear regression the model is a weighted sum — predict y as wx + b — and "learning" means finding the w and b that make the predictions least wrong on the training data.

"Least wrong" needs a definition, and that is the loss function. Mean squared error averages the squared gaps between predictions and truth. Squaring does two jobs: errors in both directions count, and large misses count disproportionately. With a loss defined, learning stops being mystical — it is minimization, full stop.

Gradient descent is the minimizer. The gradient of the loss with respect to each parameter says which direction increases the loss; step the opposite way, scaled by a learning rate, and repeat. The lecture derives the update rule by hand so you see there is no magic in it — two lines of calculus, applied over and over.

The practical content is in the failure modes. A learning rate too large overshoots and diverges; too small crawls. Batch descent uses every example per step and is stable but slow; stochastic descent uses one example, is noisy but fast; mini-batches split the difference and are what everyone actually uses. You will watch all three walk the same loss surface in the notebook.

What generalizes beyond regression: nearly everything ahead — logistic regression, neural networks, transformers — trains by exactly this loop. Different model, different loss, same descent.

Figure · Walk the loss surface

One parameter, one loss curve, one update rule: w ← w − lr · dL/dw. Set the learning rate and step. Find the rate that crawls, the one that converges, the one that oscillates, and the one that diverges.

Below lr ≈ 1.0 the gap to the minimum shrinks every step; above it, each step overshoots by more than it gained and the iterate explodes — the same arithmetic the lecture derives. The stochastic toggle adds noise to the gradient: the path rattles but still finds the valley, which is why mini-batches are what everyone actually uses.

Key concepts

  • Linear Regression: Predicting a continuous output as a weighted sum of inputs
  • Loss Function: A measure of prediction error (e.g., Mean Squared Error)
  • Gradient Descent: Iterative optimization by following the negative gradient
  • Learning Rate: Step size for parameter updates
  • Convergence: When the optimization reaches a minimum

From the prerequisites

  • Calculus: derivatives (rate of change of a function)
4 · Code

The lecture notebook

Six parts, from scratch before any framework. Run every cell; change things and rerun — the notebook is the lecture.

In Colab: File → Save a copy in Drive keeps your work.

5 · Practice

Exercise

Attempt the exercise before opening the solution — the attempt is where the learning happens.

6 · Check

Knowledge check

The quiz is self-graded and open-book. If a question surprises you, the corresponding lecture part is the fastest fix.

7 · Go deeper

Reference and discussion

8 · Done

Finish the module

Complete the stages above, then claim the finish here.