Foundations of Regression
Lesson 3The sigmoid function
Squashing any score into a probability between 0 and 1
The sigmoid: the secret sauce of logistic regression
The sigmoid function (also called the logistic function) is what transforms our linear model into a probability model. It has an elegant S-shaped curve that you can explore in the interactive calculator further down.
Mathematical definition
| Symbol | Meaning |
|---|---|
| z | Linear score from our model: z = wx + b in one dimension. Here m has become w and c has become b; with vectors and bias, z = wᵀx + b (in matrix form often written z = WᵀX in batch notation). |
| e | Base of the natural logarithm, e ≈ 2.718. |
| σ(z) | The output probability (strictly between 0 and 1) after squashing z. |
Key properties of the sigmoid function
Bounds the output between 0 and 1
At z = 0 the output sits at 0.5, the decision threshold between "more class 0" and "more class 1" in the usual binary setup.
Smooth and differentiable
This makes it perfect for optimization using gradient descent.
Non-linear transformation
It allows us to model non-linear relationships in the data in the sense that the probability in x is a non-linear function even when z is linear in x.
Some other examples of z
| z | σ(z) | Intuition |
|---|---|---|
| 0 | 0.5 | Neutral score, coin flip between extremes. |
| 2 | ≈ 0.88 | Strong push toward class 1. |
| −3 | ≈ 0.047 | Strong push toward class 0. |
Intuitive understanding
Think of the sigmoid function as a "squashing" mechanism:
Large positive z
Gets squashed toward 1.
z near 0
Outputs land near 0.5.
Large negative z
Gets squashed toward 0.
This means that even if our linear model produces a value like 27 or −15, the sigmoid function will convert it to a probability between 0 and 1. Try it yourself, type in any score, however extreme:
Sigmoid calculator
σ(z) = 1 / (1 + e−z) =
0.8807971
Reads as a probability that leans class 1.
However large or negative the score, the output is trapped strictly between 0 and 1, which is exactly what lets us read it as a probability.
Implement it yourself
The sigmoid is just one line of NumPy. Press Run to compute it in your browser and watch every score, even the extreme ones, land strictly inside (0, 1):
Check your understanding
1 / 11What is the value of σ(0)?
Practice it yourself
You dragged the squisher; now wire it up in code. Two Easy drills put the sigmoid to work in its logistic-regression role, with real Python and hidden tests, no setup.