Decision Boundary

What happens when a logistic regression model predicts a probability of exactly 0.5? This is precisely where the model's decision boundary lies, marking the point where it switches its classification prediction between two classes.

Visualizing Class Separation

Data Points for Two Classes
This scatter plot shows two distinct groups of data points, representing two different classes. Each point has two features, 'Feature 1' and 'Feature 2', which are used by a classification model to distinguish between the classes.
Loading chart...
Key Insight: Distinct clusters of data points represent different classes that a model aims to separate.

The Probability Threshold

Logistic regression models do not directly output class labels. Instead, they predict the probability that a given data point belongs to a specific class, often denoted as P(Y=1∣X)P(Y=1|X). This probability is a continuous value between 0 and 1.

To convert this probability into a binary class label (e.g., 0 or 1), a threshold is applied. If the predicted probability exceeds this threshold, the data point is assigned to one class; otherwise, it's assigned to the other. The standard threshold used is 0.5.

Sigmoid Function and 0.5 Probability Threshold
This chart displays the sigmoid (logistic) function, which maps any real-valued number (z, the linear combination of features) to a probability between 0 and 1. The horizontal dashed line indicates the 0.5 probability threshold, and the vertical dashed line shows that this threshold is crossed when z equals 0.
Loading chart...
Key Insight: The sigmoid function maps the linear combination of features to a probability, with 0.5 being the critical threshold when the linear combination is zero.
📐 The Decision Boundary Condition

The decision boundary for logistic regression is defined by the condition where the predicted probability of belonging to the positive class is exactly 0.5:

P(Y=1∣X)=0.5P(Y=1|X) = 0.5

Since the sigmoid function σ(z)=11+e−z\sigma(z) = \frac{1}{1 + e^{-z}} equals 0.5 when z=0z=0, the decision boundary is equivalently defined by the linear combination of features being zero:

z=β0+β1x1+β2x2+⋯+βnxn=0z = \beta_0 + \beta_1 x_1 + \beta_2 x_2 + \dots + \beta_n x_n = 0

Decision Boundary
The decision boundary is a hyperplane (a line in 2D, a plane in 3D, or a higher-dimensional equivalent) that separates the feature space into regions where a classification model predicts different classes. For logistic regression, it's the specific point where the predicted probability of a data point belonging to the positive class is exactly 0.5.
Example: Consider a model classifying emails as 'spam' or 'not spam' based on word count and sender reputation. The decision boundary would be a line (or curve) in the 2D feature space where, on one side, emails are predicted as spam, and on the other, they are predicted as not spam.
Check Your Understanding
What is the typical probability threshold used by a logistic regression model to classify a data point into the positive class?

Implementing and Visualizing the Boundary

pythonPlotting a Logistic Regression Decision Boundary
Try It Yourself
Modify the LogisticRegression model in the code example. Change the C parameter (regularization strength) to a smaller value, such as 0.1, and observe how the decision boundary changes. What effect does stronger regularization have on the boundary?
python
Key Takeaways
  • The decision boundary is the line or hyperplane where a logistic regression model switches its classification prediction.

  • It is defined by the condition where the predicted probability P(Y=1∣X)P(Y=1|X) is exactly 0.5.

  • This probability threshold corresponds to the linear combination of features (zz) being equal to zero.

  • For basic logistic regression, the decision boundary is always linear in the feature space.

  • Visualizing the decision boundary helps understand how the model separates different classes.

Try it yourself

Logistic Regression Playground

Move a decision boundary and watch log-loss respond. See what the sigmoid turns distance into, and why a confident mistake costs so much.

Open the lab

← All lessons in Logistic Regression

Ready to keep this from fading?

Bitelrn turns lessons like this into a full course — quizzes, a knowledge map, and spaced review.

Get started free