Why we need sigmoid
Pass/fail labels are 0 or 1. Raw neuron output can be -3, 0.7, or 12. We want something between 0 and 1 we can read as “chance of pass.”
Sigmoid does that:
import math
def sigmoid(x):
return 1 / (1 + math.exp(-x))
| Raw output (z) | Sigmoid | Plain read |
|---|---|---|
| -2.0 | ~0.12 | Likely fail |
| 0.0 | 0.50 | Coin flip |
| 1.2 | ~0.77 | Likely pass |
| 4.0 | ~0.98 | Very likely pass |
Raw score → probability → label
This animated concept requires JavaScript to be enabled.
Frames:
-
Raw z can be any real number—too wild for a probability.
-
Sigmoid bends z into the range (0, 1).
-
We pick 0.5 as the cutoff: at or above → Pass, below → Fail.
Make a prediction
raw_output = 1.2
probability = sigmoid(raw_output)
print(probability) # ~0.7685
if probability >= 0.5:
print("Pass")
else:
print("Fail")
The model is not thinking. It applies a formula, then compares to a line you chose (0.5). Different problems use different thresholds; 0.5 is the usual teaching default.
Full forward pass in one snippet
import math
def sigmoid(x):
return 1 / (1 + math.exp(-x))
study_hours = 3
weight = 0.5
bias = -1
raw = study_hours * weight + bias
prob = sigmoid(raw)
print("raw:", raw)
print("probability:", round(prob, 4))
print("label:", "Pass" if prob >= 0.5 else "Fail")
import math
def sigmoid(x):
return 1 / (1 + math.exp(-x))
def predict_pass(study_hours, weight, bias):
raw = study_hours * weight + bias
prob = sigmoid(raw)
label = "Pass" if prob >= 0.5 else "Fail"
return label, prob
print(predict_pass(2, 0.5, -1))
print(predict_pass(3, 0.5, -1))
Live runner — tweak hours
Exercise 2 — uncertain zone
Run with study_hours = 2.5, weight = 0.5, bias = -1.
Question: Is the probability close to 0.5? Why does that feel like “unsure”?
Answer
raw = 2.5×0.5 - 1 = 0.25, sigmoid(0.25) ≈ 0.56—just above 0.5. Small changes in hours or weights could flip the label. That is uncertainty, not the model “being shy.”
Key takeaways
- Sigmoid maps any real number into (0, 1).
- Threshold 0.5 turns probability into Pass/Fail.
- Predictions are math + a rule—not reasoning.
Next: when the prediction is wrong, we measure loss and start training.