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! 🚀
Neural Networks Overview
Neural networks are the core building blocks of deep learning. They are loosely inspired by the structure of the human brain, using interconnected units called neurons to process information.
What is a Neural Network?
A neural network is a mathematical system made up of layers of connected units called neurons.
Input layer: receives the raw data (pixels of an image, words of a sentence, etc.)
Hidden layers: process the information, each layer learning increasingly complex patterns
Output layer: produces the final result (like 'cat' or 'dog' for image classification)
The network learns by adjusting the connections (called weights) between neurons based on the errors it makes during training.
Deep Learning ⊂ Machine Learning ⊂ Artificial Intelligence
A Very Simple Neural Network
# Simplest possible neural network: one neuron
# It takes inputs, applies weights, and produces an output
def single_neuron(inputs, weights, bias):
"""
inputs: list of numbers [x1, x2, x3, ...]
weights: how much each input matters [w1, w2, w3, ...]
bias: adjustment value
output: a single number
"""
# Multiply each input by its weight and sum them up
weighted_sum = sum(x * w for x, w in zip(inputs, weights))
weighted_sum += bias
# Apply activation: output 1 if sum > 0, else 0
output = 1 if weighted_sum > 0 else 0
return output
# Example: predict if a student will pass
# Inputs: [study_hours, attendance_percent]
inputs = [6, 85] # 6 hours study, 85% attendance
weights = [0.3, 0.05] # study hours matter more
bias = -5.0 # threshold adjustment
result = single_neuron(inputs, weights, bias)
print(f"Study hours: {inputs[0]}, Attendance: {inputs[1]}%")
print(f"Neural network output: {result}")
print(f"Prediction: {'Pass' if result == 1 else 'Fail'}")
# Multiple examples
test_cases = [
([2, 40], "Low study, low attendance"),
([8, 90], "High study, high attendance"),
([4, 70], "Medium study, medium attendance"),
]
print()
print("Multiple student predictions:")
for inp, description in test_cases:
output = single_neuron(inp, weights, bias)
print(f" {description}: {'Pass' if output == 1 else 'Fail'}")