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
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 . 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.
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:
Since the sigmoid function equals 0.5 when , the decision boundary is equivalently defined by the linear combination of features being zero:
Implementing and Visualizing the Boundary
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?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 is exactly 0.5.
This probability threshold corresponds to the linear combination of features () 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