Module 2 · Classifiers and generalisation · Lesson 4
Logistic regression, step by step
From a weighted sum to a probability with the sigmoid, the cross-entropy loss and its gradient (the same shape as linear regression), a classifier you train in numpy and match against scikit-learn, and the softmax that turns it into a multi-class model and an LLM's output head.
By the end of this lesson you can
- Derive the sigmoid from log-odds and compute P(urgent | features) for a ticket by hand from weights and a bias
- Write the binary cross-entropy loss, explain why squared error is the wrong loss for probabilities, and show its gradient has the same form as linear regression's
- Train logistic regression with your own numpy gradient descent and match scikit-learn's decisions on at least 95% of validation tickets
- Extend the model to several classes with softmax and read the learned weights as evidence per word
- Explain why an LLM's next-token layer is a softmax regression over the vocabulary
