Logistic regression
Step 7 of 21 in Machine Learning · Build · Easy
A linear score squashed through a sigmoid into a probability, trained with log-loss. The baseline classifier for almost everything.
Guess first
A spam model computes a score of 3.2 for an email. What does logistic regression turn that score into?
- A class label: spam or not spam
- A probability between 0 and 1
- A score between −1 and 1
Show the answer
A probability between 0 and 1. The sigmoid squashes any score into (0, 1): 3.2 becomes about 0.96, a 96% chance of spam. The label comes afterwards, by comparing that probability to a threshold, usually 0.5.
Read this
An Introduction to Statistical Learning, §4.3 Logistic Regression. Read 4.3.1 to 4.3.3: the logistic model, estimating the coefficients, making predictions. Skip the lab for now; the problems below replace it.
Build it
From scratch
Sigmoid, binary cross-entropy and gradient descent on the breast-cancer dataset; plot the loss curve.
Done when: Accuracy within 2% of sklearn.
Decision boundary
Train on 2 features and plot the boundary.
Done when: Boundary is where p = 0.5.
Resources
- Wikipedia: Logistic regression Article
- ISLR / ISLP (free book) Book
- StatQuest Video
- scikit-learn: model evaluation Article
Earn this star
On the map, you log what you built. Finish the step and its star lights.
Open this step on the map