A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Logistic Regression for Classification

Graduate Depth 93 in the knowledge graph ☐ I know this ☆ Set as goal
1topic build on this
647prerequisites beneath it
See this on the map →
Linear Regression in Machine LearningConditional Probability+6 more→→Imbalanced Classification and Class Weighting
supervised-learning classification probabilistic

Core Idea

Logistic regression outputs class probabilities via the logistic function applied to linear combinations of features. Cross-entropy loss is minimized via gradient descent. Despite its name, it is a classification algorithm modeling P(y=1|x).

How It's Best Learned

Implement logistic regression with cross-entropy loss, visualize decision boundaries on 2D data, and compare ROC curves.

Common Misconceptions

Logistic regression outputs probabilities, not binary labels; thresholding is needed for classification. It assumes linear separability; overlapping classes degrade performance.

Explainer

You already know how linear regression fits a line to predict a continuous value. Logistic regression starts from the same foundation — a linear combination of features, w₁x₁ + w₂x₂ + ... + b — but asks a different question: instead of "what value?", it asks "which class?" The problem is that a raw linear combination can produce any real number, while a probability must stay between 0 and 1. The logistic function (also called the sigmoid), σ(z) = 1/(1 + e⁻ᶻ), solves this by squashing any real-valued input into the (0, 1) range. Feed the linear combination through the sigmoid, and you get P(y = 1 | x) — the model's estimated probability that the input belongs to the positive class.

This probabilistic output is what makes logistic regression fundamentally different from just drawing a dividing line. The model does not output "yes" or "no" directly; it outputs a number like 0.82, meaning "82% chance of class 1." You choose a decision threshold (typically 0.5) to convert this probability into a hard prediction, but the threshold is a separate design choice. Moving it up or down trades off precision against recall — something you can visualize with an ROC curve. The decision boundary itself — the set of points where P(y = 1 | x) = 0.5 — is always a straight line (or hyperplane in higher dimensions), because it corresponds to the set of inputs where the linear combination equals zero.

Training logistic regression means finding the weights that make the model's predicted probabilities match the observed labels as closely as possible. The right loss function here is cross-entropy loss (also called log loss), not squared error. Cross-entropy penalizes confident wrong predictions severely: if the model says P(y = 1) = 0.99 but the true label is 0, the loss is enormous. This is derived from maximum likelihood estimation — you are maximizing the likelihood of the observed data under the model. Since the sigmoid and logarithm are both differentiable, you can compute gradients of the cross-entropy loss with respect to each weight using the chain rule, and then apply gradient descent to update the weights iteratively.

Despite its simplicity, logistic regression is a powerful and interpretable baseline. Each weight tells you how much a one-unit increase in that feature shifts the log-odds of the positive class. It works well when the true decision boundary is approximately linear, scales efficiently to large datasets, and rarely overfits when properly regularized. Its limitations are equally instructive: because the decision boundary must be linear, logistic regression cannot capture XOR-like patterns or complex nonlinear boundaries without manual feature engineering. This limitation is precisely what motivates the move to neural networks — which you can think of as stacking many logistic-regression-like units together with nonlinearities between them.

Practice Questions 5 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Dividing Integers → Unit Rates → Proportions → Percent Concept → Converting Between Fractions, Decimals, and Percents → Operations with Rational Numbers → Two-Step Equations → Solving Multi-Step Equations → Equations with Variables on Both Sides → Angle Pairs: Complementary, Supplementary, and Vertical → Parallel Lines and Transversals → Corresponding Angles → Alternate Interior Angles → Triangle Angle Sum Theorem → Exterior Angle Theorem → Triangle Inequality Theorem → Similar Triangles: AA Similarity → Similar Triangles: SSS and SAS Similarity → Proportions in Similar Triangles → Right Triangle Trigonometry Introduction → Sine, Cosine, and Tangent Ratios → Trigonometric Ratios Review → Radian Measure → Converting Between Degrees and Radians → The Unit Circle → Graphing Sine and Cosine → Graphing Tangent and Reciprocal Trigonometric Functions → Derivatives of Trigonometric Functions → Antiderivatives → Indefinite Integrals → Basic Integration Rules → Riemann Sums → Definite Integral Definition → Probability Density Functions and Continuous Distributions → Cumulative Distribution Functions → Continuous Random Variables → Probability Density Functions → Expected Value → Weak Law of Large Numbers → Probability Axioms and Rules → Conditional Probability → Logistic Regression for Classification

Longest path: 94 steps · 647 total prerequisite topics

Prerequisites (8)

Leads To (1)