Beginner-Friendly Topic
Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on. You've got this! 🚀
Bias
Bias is a number added to the weighted sum in every neuron. It gives the network flexibility to shift its output, making it easier to fit many different patterns.
Why Bias Matters
Without bias, a neuron can only produce zero when all inputs are zero. With bias, the neuron can produce non-zero outputs even with zero inputs.
A simple analogy: imagine a see-saw. Weights control how much each side is pushed down. Bias is like adding a fixed weight to one side to shift the balance point.
In practice, bias allows the network to model situations where the baseline prediction is not zero. For example: even if a student studies zero hours, there is still some baseline probability of passing (they might already know the material).
Deep Learning ⊂ Machine Learning ⊂ Artificial Intelligence
Bias in Code
# Demonstrating the effect of bias
def neuron_output(x, weight, bias):
"""z = weight * x + bias"""
z = weight * x + bias
return max(0, z) # ReLU activation
# Without bias (bias = 0)
print("Without bias:")
for x in [0, 1, 2, 5, 10]:
output = neuron_output(x, weight=1.0, bias=0)
print(f" x={x} -> output={output:.1f}")
print()
# With positive bias (shifts activation threshold down)
print("With positive bias (+3):")
for x in [0, 1, 2, 5, 10]:
output = neuron_output(x, weight=1.0, bias=3)
print(f" x={x} -> output={output:.1f}")
print()
# With negative bias (shifts activation threshold up)
print("With negative bias (-3): neuron fires only for larger inputs")
for x in [0, 1, 2, 5, 10]:
output = neuron_output(x, weight=1.0, bias=-3)
print(f" x={x} -> output={output:.1f}")