Multi Layer Neural Network for XOR Classification with Visualization
Experiment
Multi Layer Neural Network for XOR Classification with Visualization
🎯 Objective
- Implement a simple neural network from scratch
- Train it on XOR logic
- Visualize:
- Loss curve
- Decision boundary
Theory
🔹 1. Neural Network Overview
A Neural Network consists of layers of neurons:
- Input Layer → receives data
- Hidden Layer → processes data
- Output Layer → produces prediction
Each connection has:
- Weight (W) → importance of input
- Bias (b) → adjusts output
🔹 2. Forward Pass
Forward pass is the process of computing the output from input.
Hidden Layer:
Output Layer:
👉 is the predicted output.
🔹 3. Sigmoid Activation Function
The sigmoid function converts values into range (0,1):
Properties:
- Smooth and differentiable
- Used for binary classification
Derivative:
🔹 4. Loss Function
We use Mean Squared Error (MSE):
🔹 5. Backpropagation
Backpropagation is used to update weights by propagating error backward.
Output Layer Error:
Hidden Layer Error:
🔹 6. Weight Update Rule
Weights are updated using gradient descent:
Output Weights:
Hidden Weights:
👉 = learning rate
📊 Dataset (XOR Problem)
| x1 | x2 | y |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
🧠 Concept
- 2 input neurons
- 1 hidden layer (2 neurons)
- 1 output neuron
- Sigmoid activation
💻 Program
1. Loss Visualization
2. Decision Boundary Visualization

Result
- Neural network correctly learns XOR logic
- Loss decreases over epochs
- Decision boundary clearly separates classes

Comments
Post a Comment