Home / Maths for AI / Symbols / Functions

Sigmoid function

Say it: "sigma of z", "sigmoid of z"

What it means

σ(z)=11+e−z\sigma(z) = \frac{1}{1 + e^{-z}} squashes any number into the range 0 to 1. (The same letter σ\sigma also means standard deviation; context tells you which.)

Example

σ(0)=0.5,σ(4)≈0.982\sigma(0) = 0.5, \quad \sigma(4) \approx 0.982

Large inputs go towards 1, negative ones towards 0.

In code

import numpy as np
sigmoid = lambda z: 1 / (1 + np.exp(-z))
print(sigmoid(np.array([-4, 0, 4])).round(3))

Output

[0.018 0.5   0.982]

Where it appears in machine learning

Turns a score into a probability in logistic regression and in the last layer of binary classifiers.

Related symbols

Learn it properly in the free lesson Derivatives & the Chain Rule, with practice questions that check your answers.