Learn with Yasir

Share Your Feedback

Sigmoid Function


Sigmoid Function

πŸ“Œ What is the 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.


2️⃣ Why Do We Need the Sigmoid Function?

In Machine Learning, many problems require answers like:

  • Yes / No
  • True / False
  • Pass / Fail
  • Spam / Not Spam

Numbers like -5, 10, or 100 are not useful for these decisions.

πŸ“Œ The sigmoid function fixes this problem by converting numbers into probabilities.


3️⃣ Sigmoid Function Formula

[ \text{Sigmoid}(z) = \frac{1}{1 + e^{-z}} ]

Where:

  • z = input value (can be any number)
  • e β‰ˆ 2.718 (a mathematical constant)

4️⃣ What Does the Sigmoid Function Do?

Input (z) Output
-10 0.000
-2 0.12
0 0.50
2 0.88
10 0.999

πŸ“Œ Key idea:

  • Large negative β†’ close to 0
  • Zero β†’ 0.5
  • Large positive β†’ close to 1

5️⃣ Shape of Sigmoid Function

  • Looks like a smooth S-shaped curve
  • Left side β†’ flat near 0
  • Middle β†’ steep rise
  • Right side β†’ flat near 1

This makes it perfect for classification problems.


6️⃣ Real-Life Example

πŸŽ“ Student Pass / Fail

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

7️⃣ Where Is Sigmoid Used?

βœ” Logistic Regression βœ” Binary Classification βœ” Neural Networks (activation function) βœ” Data Science decision models


8️⃣ Simple Python Example

import math

def sigmoid(z):
    return 1 / (1 + math.exp(-z))

print(sigmoid(-2))
print(sigmoid(0))
print(sigmoid(2))

9️⃣ Advantages of Sigmoid Function

βœ… Output between 0 and 1 βœ… Easy to understand βœ… Works well for probabilities βœ… Smooth and continuous


πŸ”Ÿ Limitations (Beginner Note)

❌ Can be slow for deep neural networks ❌ Suffers from vanishing gradient problem ❌ Mostly used for binary outputs


⭐ Key Points

  • Sigmoid converts numbers into probabilities
  • Output range is 0 to 1
  • Used mainly in Logistic Regression
  • Decision boundary is 0.5
  • Shape is S-curve

πŸ“ˆ Sigmoid Curve (Logistic Function)

The sigmoid curve is an S-shaped curve used in Logistic Regression to convert values into probabilities between 0 and 1.


1️⃣ What is a Sigmoid Curve?

The sigmoid function maps any real number into a value between 0 and 1.

πŸ“Œ Formula

[ \sigma(z) = \frac{1}{1 + e^{-z}} ]

Where:

  • z = weighted sum of inputs
  • e = Euler’s number (β‰ˆ 2.718)

2️⃣ Why Do We Use the Sigmoid Curve?

Because classification problems need:

  • βœ” Probabilities
  • βœ” Clear decision boundary (Yes/No)

πŸ“Œ Output interpretation:

  • Close to 0 β†’ Class 0 (No)
  • Close to 1 β†’ Class 1 (Yes)

3️⃣ Shape of Sigmoid Curve (Easy Explanation)

z value Sigmoid Output
-∞ 0
-2 0.12
0 0.5
+2 0.88
+∞ 1

πŸ“ˆ Key features

  • Smooth S-shape
  • Center point at 0.5
  • Never touches exactly 0 or 1

4️⃣ Classroom Example (Pass / Fail)

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

5️⃣ Visual Description (For Notes)

Imagine:

  • Left side β†’ flat near 0
  • Middle β†’ steep increase
  • Right side β†’ flat near 1

This makes classification stable and reliable.


6️⃣ Simple Python Code to Plot Sigmoid Curve

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

7️⃣ Key Exam Points ⭐

  • Sigmoid converts values to probability
  • Output range: 0 to 1
  • Used in Logistic Regression
  • Decision boundary at 0.5
  • Shape is S-curve

8️⃣ One-Line Definition (For Exams)

β€œ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 πŸ‘