Module 4: Logistic Regression

This module introduces logistic regression as a machine learning method for binary classification. It examines how the sigmoid function transforms linear outputs into probabilities, how decision boundaries and thresholds shape predictions, and how model parameters are learned using gradient descent with logistic loss.

Learning Objectives

  • Explain logistic regression and identify use cases for classification.
  • Describe the role of the sigmoid function in mapping linear outputs to probabilities.
  • Interpret decision boundaries and apply classification thresholds to make predictions.
  • Compute logistic loss and understand its behavior for different prediction outcomes.
  • Apply gradient descent using the derivative of the sigmoid function to train logistic regression models.
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.

Weak Classifiers, part 4 — combining classifiers with logistic regression
2 · Listen

Orientation audio

From regression to classification: what changes, what stays, and where the threshold decision lives.

3 · Read & play

The through-line

Regression predicts a number. Classification predicts a category, and the first honest question is why not just run regression on labels 0 and 1. The lecture starts there, shows where it breaks — unbounded outputs, no probabilistic reading — and lets that failure motivate the fix.

The fix is the sigmoid: squash the linear score into (0, 1) and read the result as a probability. Logistic regression is exactly linear regression pushed through that squash. The geometry stays linear underneath — the set of points where the probability equals one half is a straight line (a hyperplane, in general), and that is the decision boundary.

A probability is not yet a decision. The threshold converts one into the other, and it is a dial, not a law of nature: lower it and you catch more positives at the cost of more false alarms. Where to set it depends on which error costs more — a question about the application, not the mathematics. Medical screening and spam filtering want different thresholds for the same model.

Training needs a loss that fits probabilities, and squared error is the wrong one — it goes non-convex through the sigmoid and its gradients vanish exactly when the model is most confidently wrong. Cross-entropy loss punishes confident wrongness hard, keeps the surface clean for gradient descent, and trains with the same update loop you derived last week.

Sigmoid, boundary, threshold, cross-entropy: four pieces, one pipeline, and the template for every classifier in the rest of the course.

Figure · The squash and the dial

Fourteen cases along one feature. The model is a linear score pushed through the sigmoid; the threshold turns probability into decision. Steer all three dials.

The boundary sits where the curve crosses the threshold — a single point here, a hyperplane in general; the geometry underneath stays linear. Fit chooses w and b (watch log-loss as you steer them); the threshold is not fit at all. It is an application decision: screening lowers it and accepts false alarms, spam filtering raises it and accepts misses.

Key concepts

  • Binary Classification: Predicting one of two classes
  • Sigmoid Function: Maps any value to range (0, 1)
  • Decision Boundary: Where the model switches predictions
  • Classification Threshold: Probability cutoff for class assignment
  • Logistic Loss: Cross-entropy loss for classification
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.