Logistic Regression › Visualizing Logistic Regression

Michael BrenndoerferJune 24, 20256 min read
Machine Learning from ScratchAll chapters
Part 4 of 9Regression Models
Chapter 37Logistic Regression › Visualizing Logistic Regression
Reading section 3 of 8 · Visualizing Logistic Regression · 6 minSection 3 of 8 · 6 min

Book contents

Section 3 of 8 · 6 min read

Logistic Regression › Visualizing Logistic RegressionOne section · Sections in this chapter3 / 8 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Let's create visualizations that show the key components of logistic regression. We'll start with the fundamental mathematical concepts and then explore the decision-making process.

Out[4]:
Visualization
Compact sigmoid curve with reference lines at probability 0.5 and eta zero, annotated probabilities near zero, 0.5, and one, and a three-entry legend beneath the plot.
This shows how the logistic function maps any real number (the linear predictor η) into a probability between 0 and 1. The S-shaped curve is steepest at η = 0 (where p = 0.5) and flattens as it approaches the extremes. This mapping keeps predictions valid probabilities.
Three-bar coefficient chart for the intercept, Feature 1, and Feature 2, with exact values 0.009, 2.475, and minus 0.394 labeled on the bars.
This shows the learned coefficients, which represent the change in log-odds for a one-unit increase in each feature. Positive coefficients increase the probability of the positive class, while negative coefficients decrease it. The intercept represents the baseline log-odds when all features are zero.

Now let's explore how logistic regression makes decisions in practice:

Out[5]:
Visualization
Decision-boundary plot of 200 observations with coral circles for class 0, blue triangles for class 1, 20 probability contour bands, a dashed 0.5 probability boundary, and a predicted-probability colorbar.
The decision boundary visualization shows how logistic regression separates classes in the feature space. The dashed line represents the 0.5 probability threshold, while the color gradient shows predicted probabilities across the feature space. Points on one side of the boundary are classified as class 0, while points on the other side are classified as class 1.
Out[6]:
Visualization
Three-dimensional logistic probability surface over Feature 1 and Feature 2 with all 200 class observations plotted at probability zero or one and a predicted-probability colorbar.
This three-dimensional view shows how the predicted probability varies across the two-dimensional feature space. The surface smoothly transitions from low probabilities (coral) to high probabilities (blue), with the steepest gradient near the decision boundary. This visualization helps understand how the logistic function creates a smooth probability landscape.