# Logistic Regression and Linear Classifiers

> Modelling class probabilities with the sigmoid and softmax, log loss, decision thresholds and calibrated linear baselines. Free notes, key concepts, resources...

Canonical: https://www.internhack.in/roadmaps/tracks/machine-learning/logistic-regression
Last updated: 2026-11-28

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](https://www.internhack.in/roadmaps/tracks/machine-learning/linear-regression), [Probability for ML](https://www.internhack.in/roadmaps/tracks/machine-learning/probability)

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 (`C` is 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](https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression) (scikit-learn)
- [Google ML Crash Course: Logistic regression](https://developers.google.com/machine-learning/crash-course) (Google)

Previous: [Linear Regression and Regularization](https://www.internhack.in/roadmaps/tracks/machine-learning/linear-regression) · Next: [k-Nearest Neighbours and Naive Bayes](https://www.internhack.in/roadmaps/tracks/machine-learning/knn-and-naive-bayes)

## More in Classical Supervised Learning

- [Framing ML Problems and the scikit-learn API](https://www.internhack.in/roadmaps/tracks/machine-learning/ml-problem-framing)
- [Linear Regression and Regularization](https://www.internhack.in/roadmaps/tracks/machine-learning/linear-regression)
- [Logistic Regression and Linear Classifiers](https://www.internhack.in/roadmaps/tracks/machine-learning/logistic-regression)
- [k-Nearest Neighbours and Naive Bayes](https://www.internhack.in/roadmaps/tracks/machine-learning/knn-and-naive-bayes)
- [Decision Trees](https://www.internhack.in/roadmaps/tracks/machine-learning/decision-trees)
- [Bagging and Random Forests](https://www.internhack.in/roadmaps/tracks/machine-learning/random-forests)
- [Gradient Boosting with XGBoost and LightGBM](https://www.internhack.in/roadmaps/tracks/machine-learning/gradient-boosting)
- [Support Vector Machines and Kernels](https://www.internhack.in/roadmaps/tracks/machine-learning/support-vector-machines)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Machine Learning Engineer Roadmap](https://www.internhack.in/roadmaps/tracks/machine-learning)
