Logistic Regression and Classification
A linear score passed through the sigmoid to give a probability, trained by minimising cross-entropy.
Needs a step first: 32
To decide yes or no, compute a score and squash it into a probability between 0 and 1. The boundary is a straight line (or flat plane) through the input space. The loss is the cross-entropy , which is the negative log-likelihood, and its gradient comes out neatly as . A logistic regression unit is one neuron; stacking many gives a neural network, and softmax extends it to many classes.
Where it shows up: Each unit of a neural network is a logistic regression with a different activation, and softmax is its many-class form.
How to hold it: In your head
See a linear score squashed by the sigmoid into a probability, the boundary as a straight line through the inputs, and the gradient as error times input.
What knowing it looks like
- Compute a logistic unit's probability, loss and gradient for one example by hand.
- Derive and the gradient .
- Draw the decision boundary of a two-input logistic model from its weights.
Test yourself
A logistic model has and . For input with label , find , , the cross-entropy loss in nats, and the gradient of the loss with respect to and . Use .
Show the worked answer
Needs a step first: 32
Learn it with an AI
Copy this prompt into any AI assistant. It will take you through step by step at your level and finish with the test above.
Be my maths tutor. I'm learning "Logistic Regression and Classification" (Undergraduate II tier): A linear score passed through the sigmoid $\sigma(z) = 1/(1 + e^{-z})$ to give a probability, trained by minimising cross-entropy.
I already know: Linear Regression as Learning, Maximum Likelihood.
Teach it Socratically: first ask what I already know; then explain the core idea with one concrete example and why it's true; then give me three problems, one at a time, easy to hard. Wait for my answer, check every step, and point out mistakes without giving the answer away.
Finish by testing me with this: A logistic model has $\vec w = (2, -1)$ and $b = 0.5$. For input $\vec x = (1, 2)$ with label $y = 1$, find $z$, $\hat p$, the cross-entropy loss in nats, and the gradient of the loss with respect to $\vec w$ and $b$. Use $e^{-0.5} \approx 0.6065$.
Use LaTeX for formulas. When you say where it's used later (machine learning, quantum mechanics), be specific.Needs first
- Linear Regression as LearningFitting by choosing the parameters that minimise the mean squared error: the simplest model that learns from data.Undergraduate II · Machine Learning
- Maximum LikelihoodEstimating a model's parameters by choosing the values that make the observed data most probable.Undergraduate II · Probability & Statistics
Leads to
On the way to
Recommended
- Neural Networks: Zero to HeroAndrej Karpathy · VideosFree lectures that build backpropagation, a language model and a small GPT from scratch in Python, explaining every line.
- Understanding Deep LearningSimon J. D. Prince (MIT Press) · BookA clear, well-illustrated 2023 textbook covering networks, training, transformers, diffusion models and reinforcement learning, free as a PDF with Python notebooks.
- 动手学深度学习阿斯顿·张、李沐等 · Book · 中文The Chinese edition of Dive into Deep Learning: a free textbook in which every model, from linear regression to transformers, runs as code beside the maths.
- 跟李沐学AI李沐 · Videos · 中文Mu Li's own Bilibili channel: the video course for Dive into Deep Learning and paragraph-by-paragraph readings of key papers, including the Transformer paper.