Learning Objectives
By the end of this lesson, you should understand:- Neurons, weights, and biases
- Input, hidden, and output layers
- Activation functions
- ReLU
- Sigmoid
- Softmax
- Forward propagation
- Loss functions
- Backpropagation
- Gradient descent
- Learning rate
- Epochs, batches, and iterations
- Overfitting and underfitting
- Basic neural-network implementation in Python
1. What is a Neural Network?
A neural network is a machine-learning model made up of interconnected neurons arranged in layers. A typical neural network looks like:2. Artificial Neuron
A neuron receives inputs and performs three main operations:- Multiply inputs by weights
- Add the bias
- Apply an activation function
Simple Example
2.6.
3. Weights
A weight controls how strongly an input influences a neuron. For example:4. Bias
A bias is an additional learnable parameter added to the weighted sum.5. Input, Hidden, and Output Layers
A neural network consists of different types of layers.Input Layer
The input layer receives the features. For example, a house-price model may have:Hidden Layer
Hidden layers perform learned transformations. Example:Output Layer
The output layer produces the final prediction. Examples:Regression
Binary Classification
Multi-Class Classification
6. Neural Network Architecture Example
A simple binary-classification network:7. Activation Functions
Activation functions determine the output of a neuron after the weighted sum. They introduce non-linearity into the neural network. Without activation functions, multiple linear layers would still behave as one linear transformation. Important activation functions:- ReLU
- Sigmoid
- Softmax
8. ReLU
ReLU stands for Rectified Linear Unit.
ReLU is commonly used in hidden layers.
9. Implementing ReLU with NumPy
10. Sigmoid
The sigmoid function converts a value into the range(0, 1).
Python implementation:
11. Softmax
Softmax converts multiple scores into probabilities. Example:12. Activation Function Comparison
Typical architecture:
13. Forward Propagation
Forward propagation is the process of passing input data through the network to produce a prediction.14. Forward Propagation Through a Small Network
Consider:15. Loss Function
A loss function measures how different the prediction is from the actual target.16. Mean Squared Error
MSE is commonly used for regression. Where:17. Binary Cross-Entropy
Binary cross-entropy is commonly used for binary classification. Python:18. Backpropagation
After calculating the loss, the neural network needs to determine:Which parameters caused the error?This is done using backpropagation. The training process becomes:
19. Gradient Descent
Gradient descent is an optimization method used to reduce the loss. The basic update rule is: w_{new} ======= ## w_{old} \eta \frac{\partial L}{\partial w} Where:20. Simple Gradient Descent Example
Suppose:21. Learning Rate
The learning rate determines the size of parameter updates.Very small learning rate
Very large learning rate
Good learning rate
22. Epochs
An epoch means one complete pass through the training dataset. Example:23. Batches
A batch is a subset of the training dataset. Example:24. Iterations
An iteration is generally one parameter update using one batch. Example:25. Epoch vs Batch vs Iteration
Example:
26. Complete Neural Network Training Cycle
27. Overfitting
Overfitting happens when a model learns the training data too closely and performs poorly on unseen data. Example:28. Underfitting
Underfitting occurs when the model is too simple or has not learned enough from the data. Example:- Model too simple
- Too few training epochs
- Poor features
- Excessive regularization
29. Overfitting vs Underfitting
Conceptually:
30. How to Reduce Overfitting
Common techniques:1. More Training Data
2. Dropout
Randomly disables neurons during training.3. Regularization
Common methods:4. Early Stopping
Stop training when validation performance stops improving.5. Reduce Model Complexity
For example:31. Complete Neural Network Example with Scikit-Learn
We can use theMLPClassifier from scikit-learn to build a simple neural network.
Step 1: Import Libraries
32. Load Dataset
We will use the Iris dataset.33. Split the Dataset
34. Feature Scaling
Neural networks generally benefit from appropriately scaled input features.35. Build the Neural Network
36. Train the Model
37. Make Predictions
38. Evaluate Accuracy
39. Classification Report
40. Complete Code
The entire example can be written as:41. Understanding the Code
The important parameters are:hidden_layer_sizes
activation
solver
learning_rate_init
max_iter
42. Viewing Training Loss
MLPClassifier stores the training loss history in loss_curve_.
43. Predict Probabilities
For classification, we can also obtain class probabilities.1.
44. Architecture Summary
For our Iris model:45. Important Formulas
Neuron
ReLU
Sigmoid
Softmax
MSE
Gradient Descent
w_{new} ======= ## w_{old} \eta \frac{\partial L}{\partial w}46. Neural Network Training Pipeline
47. Quick Revision
48. Day 22 Mental Model
The entire concept can be remembered with this flow:Core idea: A neural network learns by making predictions, measuring its errors, calculating gradients through backpropagation, and updating its parameters to reduce the loss.