Foundations of Regression

Lesson 3

The 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

σ(z)=11+ez\sigma(z) = \frac{1}{1 + e^{-z}}
SymbolMeaning
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

As z,σ(z)0(very large negative z)\text{As } z \to -\infty,\quad \sigma(z) \to 0 \qquad\text{(very large negative } z\text{)} As z+,σ(z)1(very large positive z)\text{As } z \to +\infty,\quad \sigma(z) \to 1 \qquad\text{(very large positive } z\text{)} When z=0,σ(z)=12=0.5\text{When } z = 0,\quad \sigma(z) = \frac{1}{2} = 0.5

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
00.5Neutral score, coin flip between extremes.
2≈ 0.88Strong push toward class 1.
−3≈ 0.047Strong 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.

00.51−10+10

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):

Python
First run loads the Python runtime (~10 MB) — takes ~5–10 seconds. Subsequent runs are instant.

Check your understanding

1 / 11

What 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.

Test your understanding

Prof is ready

Prof will ask you questions about The sigmoid: the secret sauce of logistic regression — not explain it. You'll be surprised what you don't know until you have to say it.

Finished this lesson?

Read through the lesson first (0/20s).