Visual explainer
Logistic Regression
Learn an affine score and map it through sigmoid to predict binary probabilities, then use a separate threshold to choose a class.
Logistic regression learns a weighted input score, converts it into a binary class probability, and uses a separate threshold to choose an action. The circles above represent observed class 1; crosses represent class 0. A probability must lie between 0 and 1.
The drawn affine score is an illustrative contrast, not a trained logistic model. At inputs −2 and 2, it returns −0.3 and 1.3. Those are valid scores but invalid probabilities. Input and feature values throughout this page are unitless synthetic examples.
Combine Features Into A Score
Now use one fixed two-feature model: weights , bias , and input . The raw score, also called a logit, is . The measured horizontal jumps add the contributions: start at 0, add to reach 2, add another to reach 4, then add bias −2 to return to score 2.
Each row uses the same score scale. Dashed vertical links copy the accumulated score to the next row; they do not add anything. The drawing labels x1 and x2 identify the two weighted feature contributions. A score is not yet a probability.
Map Score To Probability
For binary logistic regression, . The horizontal axis is score, not either original feature. Substitution gives , , and . The curve is drawn from checked sigmoid samples; every finite score maps strictly between zero and one. Extreme scores approach the endpoints without reaching them mathematically.
This model learns its score parameters using a classification objective. It does not first fit a least-squares line and then bend that fit. The official logistic-regression reference gives the probability model and its training objective.
Split One Unit Of Probability
For our score 2, the large segment represents and the striped complement represents . Both share one fixed-length whole, and their lengths add exactly to it. The circle/cross identities match the observed classes.
Probability and odds differ. The probability here is about 0.88. The corresponding odds are to one. A bounded probability estimate can still disagree with observed frequencies; we check that separately below.
Price A Confident Mistake
Hold the observed target fixed at . Compare predictions and on the same loss scale. The positive-target loss is , giving approximately 2.126928 for the low probability and 0.126928 for the high probability. The displayed bar labels round the probabilities and losses; geometry uses the unrounded values.
For either binary target, the loss is , where is the natural logarithm. Training minimizes an aggregate of these losses, optionally with a regularization penalty. When , a large predicted probability for class 1 is the costly mistake instead.
Follow One Checked Update
Use our input (2,2), initial score 2, and known target 1. For this single unregularized example, the weight gradient is and the bias gradient is . With step size and , subtracting the gradients gives
The new score is , giving . Both probability tracks use the full 0–1 scale; the dashed reference retains the old endpoint. This sample's loss falls from about 0.126928 to 0.0761735. One update improves this sample; it does not establish a full-dataset optimum or describe a library's default optimizer.
Where Is The Boundary?
Freeze the updated weights and bias from the previous beat. With threshold 0.5, the separator satisfies , equivalently . Here that means
The feature axes use equal scales. The arrow is perpendicular to the separator and points toward increasing score; its drawn length is illustrative, while its direction is exact. The marked (2,2) sample lies on that side and has probability about 0.927. We choose class 1 when , including equality, and class 0 otherwise. Software may use a different tie convention. Applying sigmoid changes score values into probabilities but leaves this threshold boundary straight in the given features.
Change The Action Threshold
This separate policy example holds a case's estimated probability at 0.62. At cutoff 0.5, it receives the positive action; at cutoff 0.7, it receives the negative action. The aligned dots and their dashed link show that the estimated probability never changes. Since the true target is unknown here, neither action can be called a corrected mistake.
A cutoff expresses a decision policy. Choosing it requires an appropriate metric or cost model and evaluation data separate from model training. Changing a cutoff does not calibrate the probabilities. Official threshold guidance explains the separation between estimates and decisions.
Check Probability Reliability
Consider a new illustrative bin of ten cases, each assigned probability 0.8. Five circles are observed positives and five crosses are observed negatives, giving an observed positive fraction . The plotted bin therefore sits at (0.8,0.5), below the dashed equality line. Its probability values are valid, yet their average exceeds the observed fraction in this bin.
A reliability diagram compares mean predicted probability with the observed positive fraction in each bin. One small synthetic bin cannot establish model-wide miscalibration; real checks need representative evaluation data and enough cases to understand sampling variation. Official calibration guidance describes this diagnostic.
Where It Breaks
This last beat switches to a new feature arrangement: one class 0 cross at (0,0), surrounded by class 1 circles at (−2,0), (2,0), (0,−2), (0,2). The illustrated candidate calls class 1 for and class 0 otherwise. The in-scene class labels name predicted regions; circles and the cross retain their observed targets. The candidate gets the center and rightmost circle correct but misses the three circled outer samples. Amber rings mark errors, not additional observations.
Tilting the line cannot solve the entire arrangement. For any affine score, the center's score is the average of the scores at an opposite pair of ring points. If both opposite points satisfy the positive threshold, their center must also satisfy it. Thus a single affine cut cannot include the whole ring while excluding its center. This does not mean every candidate cut must misclassify both classes.
A nonlinear feature such as changes what a linear cut can represent in the original coordinates. The limitation applies to logistic regression on these raw features, not every transformed-feature version of the method.
The Quick Version
- Unbounded affine scores can fall outside the probability range.
- Weighted feature contributions and bias combine into one raw score.
- Sigmoid maps score zero to probability one-half.
- Binary class probabilities are complements; probability is not odds.
- Log loss penalizes confident predictions that contradict the target.
- A checked gradient step improves this single positive example.
- Threshold one-half gives a straight boundary in the supplied features.
- Moving the cutoff changes actions without changing probabilities.
- Reliability checks compare predicted probabilities with observed positive fractions.
- A raw-feature straight cut cannot enclose a ring around its center.