Intermediate 25 min

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)SigmoidPlain read
-2.0~0.12Likely fail
0.00.50Coin flip
1.2~0.77Likely pass
4.0~0.98Very likely pass

Raw score → probability → label

This animated concept requires JavaScript to be enabled.

Frames:

  1. Raw z can be any real number—too wild for a probability.

    Raw z can be any real number—too wild for a probability.

  2. Sigmoid bends z into the range (0, 1).

    Sigmoid bends z into the range (0, 1).

  3. We pick 0.5 as the cutoff: at or above → Pass, below → Fail.

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

            

Live runner — tweak hours

🐍 Python Sigmoid + threshold
📟 Console Output
Run code to see output...

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

  1. Sigmoid maps any real number into (0, 1).
  2. Threshold 0.5 turns probability into Pass/Fail.
  3. Predictions are math + a rule—not reasoning.

Next: when the prediction is wrong, we measure loss and start training.