Sigmoid Function
The sigmoid function is a mathematical function that converts any number into a value between 0 and 1.
π That value can be understood as a probability.
In Machine Learning, many problems require answers like:
Numbers like -5, 10, or 100 are not useful for these decisions.
π The sigmoid function fixes this problem by converting numbers into probabilities.
[ \text{Sigmoid}(z) = \frac{1}{1 + e^{-z}} ]
Where:
z = input value (can be any number)e β 2.718 (a mathematical constant)| Input (z) | Output |
|---|---|
| -10 | 0.000 |
| -2 | 0.12 |
| 0 | 0.50 |
| 2 | 0.88 |
| 10 | 0.999 |
π Key idea:
This makes it perfect for classification problems.
Suppose a model calculates:
z = study_hours Γ weight + bias
| z value | Probability | Decision |
|---|---|---|
| -1.5 | 0.18 | Fail |
| 0.0 | 0.50 | Borderline |
| 2.0 | 0.88 | Pass |
π Rule:
If probability β₯ 0.5 β Pass
Else β Fail
β Logistic Regression β Binary Classification β Neural Networks (activation function) β Data Science decision models
import math
def sigmoid(z):
return 1 / (1 + math.exp(-z))
print(sigmoid(-2))
print(sigmoid(0))
print(sigmoid(2))
β Output between 0 and 1 β Easy to understand β Works well for probabilities β Smooth and continuous
β Can be slow for deep neural networks β Suffers from vanishing gradient problem β Mostly used for binary outputs
The sigmoid curve is an S-shaped curve used in Logistic Regression to convert values into probabilities between 0 and 1.
The sigmoid function maps any real number into a value between 0 and 1.
[ \sigma(z) = \frac{1}{1 + e^{-z}} ]
Where:
z = weighted sum of inputse = Eulerβs number (β 2.718)Because classification problems need:
π Output interpretation:
| z value | Sigmoid Output |
|---|---|
| -β | 0 |
| -2 | 0.12 |
| 0 | 0.5 |
| +2 | 0.88 |
| +β | 1 |
π Key features
| Study Hours (z) | Probability of Pass |
|---|---|
| 1 | 0.20 |
| 2 | 0.35 |
| 3 | 0.50 |
| 4 | 0.75 |
| 5 | 0.90 |
π Decision rule:
Probability β₯ 0.5 β Pass
Else β Fail
Imagine:
This makes classification stable and reliable.
import numpy as np
import matplotlib.pyplot as plt
z = np.linspace(-10, 10, 100)
sigmoid = 1 / (1 + np.exp(-z))
plt.plot(z, sigmoid)
plt.xlabel("z")
plt.ylabel("Sigmoid(z)")
plt.title("Sigmoid Curve")
plt.show()
βThe sigmoid curve is an S-shaped function that converts input values into probabilities between 0 and 1.β
If you want: π Ready-made sigmoid image for notes π§ MCQs on sigmoid function π Short/long exam answers π Student worksheet
Just tell me π