Logit and sigmoid
Quick answer
Logistic regression is a classification model. For a binary outcome it converts a linear score into an estimate of the probability of class 1 using a sigmoid. The score is linear in the features, but the probability is not. Examples run locally with Python 3.13.5, scikit-learn 1.8.0, NumPy 2.3.5 and SciPy 1.17.0 when imported. ByteMind library execution is unverified.
Turn a linear score into a probability
from math import expx, w, b = 2, 0.5, -1z = b + w*xprint(z, round(1/(1+exp(-z)), 6))Expected output:
0.0 0.5The linear score cancels to zero, so the two class estimates are equal.
How it works
A fictional device sends a diagnostic message. Let x be its measured vibration score and y be 1 if inspection finds a fault, otherwise 0. A model with intercept b and weights w computes z = b + w·x. The sigmoid p = 1/(1+exp(-z)) maps any finite real score to a probability mathematically between zero and one. Odds are p/(1-p); the logit is ln(odds) and equals z under this model. If a coefficient is 0.7, raising its feature by one unit while holding others fixed multiplies the modeled odds by exp(0.7), not the probability by 0.7. This interpretation is conditional association, not a causal effect. At z=0 the odds are 1 and p=0.5. At z=ln(3), p=0.75. The derivative dp/dz=p(1-p) is largest at zero and shrinks near either extreme. In floating point, very large scores may round to 0 or 1. Compute the sigmoid in branches so that exp never receives a large positive argument. Fitting estimates b and w from labeled training data by minimizing an objective; this lesson uses known weights first. The next lesson introduces the loss.
Compute safely at extreme scores
from math import expdef sigmoid(z): if z >= 0: return 1/(1+exp(-z)) e = exp(z) return e/(1+e)print([round(sigmoid(z), 6) for z in [-1000, -1, 0, 1, 1000]])Expected output:
[0.0, 0.268941, 0.5, 0.731059, 1.0]The extreme rounded values are numerical saturation, not proof that the real event is impossible or certain.
Common mistakes
Do not pass z directly as a probability or treat a coefficient as a percentage-point change. Do not compute exp(-z) for very negative z without a stability guard. Check the class convention before interpreting any score.
Practice and next steps
For b=-1 and w=0.5, compare x=0 and x=4; predict which has larger odds and why. Then implement the stable sigmoid. Complete the knowledge check and coding exercise. Next: Binary cross entropy.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Logit and sigmoid — knowledge check
Apply logit and sigmoid to new examples.
What is the probability at score 0?
What does a coefficient of ln(2) mean for a one-unit feature increase?
Which input causes exp(-z) overflow in a naive sigmoid?
What is the logit of p=0.75?
A sigmoid output rounds to 1.0. What follows?