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! 🚀
Weights
Weights are the numbers that control how strongly each input influences the output of a neuron. Learning in a neural network means finding the right weights.
What Weights Do
Imagine you are trying to predict whether a student will pass an exam. You consider two factors: study hours and attendance.
If you think study hours matter twice as much as attendance, you would weight study hours more heavily.
In a neural network:
- A high weight means that input has a strong influence on the output
- A low weight (near zero) means that input barely matters
- A negative weight means the input reduces the output
During training, the network automatically learns which inputs should have high, low, or negative weights.
Deep Learning ⊂ Machine Learning ⊂ Artificial Intelligence
Weights in Action
# Demonstrating how weights affect the output
def weighted_prediction(study_hours, attendance_pct, w_study, w_attendance, bias):
"""Calculate prediction with given weights."""
score = study_hours * w_study + attendance_pct * w_attendance + bias
return score
# Scenario 1: study hours weighted heavily
print("Scenario 1: Study hours weighted heavily")
score = weighted_prediction(8, 50, w_study=2.0, w_attendance=0.1, bias=-5)
print(f" 8h study, 50% attendance -> score: {score:.1f}")
score = weighted_prediction(2, 90, w_study=2.0, w_attendance=0.1, bias=-5)
print(f" 2h study, 90% attendance -> score: {score:.1f}")
print()
# Scenario 2: attendance weighted heavily
print("Scenario 2: Attendance weighted heavily")
score = weighted_prediction(8, 50, w_study=0.1, w_attendance=0.1, bias=-5)
print(f" 8h study, 50% attendance -> score: {score:.1f}")
score = weighted_prediction(2, 90, w_study=0.1, w_attendance=0.1, bias=-5)
print(f" 2h study, 90% attendance -> score: {score:.1f}")
print()
print("The weights determine which factors the model thinks matter most.")
print("Training finds the weights that produce the most accurate predictions.")Tip
Tip
At the start of training, weights are set to small random numbers. The network does not know yet which inputs matter. Through training, it adjusts the weights to make better predictions. The final weights encode everything the network has learned.