Logistic Regression and Linear Classifiers
Modelling class probabilities with the sigmoid and softmax, log loss, decision thresholds and calibrated linear baselines.
Beginner · about 6 hours · difficulty 2/5
Learn first: Linear Regression and Regularization, Probability for ML
Logistic regression is the default first classifier: fast, robust, interpretable and it outputs probabilities. Understanding it deeply also means understanding the last layer of most neural network classifiers.
How it works
- Compute a linear score
z = w . x + b, squash it with the sigmoid to get a probability. - Train by minimizing log loss (binary cross-entropy), which is convex, so optimization is reliable.
- Multiclass: softmax (multinomial) regression or one-vs-rest.
- Coefficients are changes in log-odds;
exp(coef)is an odds ratio.
Practical points
- The default decision threshold of 0.5 is arbitrary. Choose a threshold from the costs of false positives and false negatives.
- Regularization is on by default in scikit-learn (
Cis the inverse strength). - Scale features, and one-hot encode categories.
- Linear decision boundaries can be made flexible with engineered or polynomial features.
Good enough to move on when you can train a logistic regression, explain a coefficient as an odds ratio, and pick a threshold that meets a target recall.
Key concepts
- Sigmoid and log-odds
- Log loss
- Softmax for multiclass
- Decision thresholds
- Regularization strength C
- Odds ratio interpretation
Mini project
Build a logistic regression on the Telco Customer Churn dataset, report the five strongest odds ratios, and choose a threshold that catches 80% of churners while reporting the resulting precision.
Check yourself
Why is log loss preferred over accuracy as the training objective for a probabilistic classifier?
Free resources
- scikit-learn: Logistic regression (scikit-learn)
- Google ML Crash Course: Logistic regression (Google)