Single Layer Neural Network for OR Gate Classification with Visualization
Experiment
Title:
Single Layer Neural Network for OR Gate Classification with Visualization
🎯 Objective
- To implement a single-layer neural network (logistic model)
-
To understand:
- Forward propagation
- Sigmoid activation
- Backpropagation
- To visualize the decision boundary (straight line)
Theory
🔹 1. Neural Network Model (Single Layer)
This is the simplest neural network:
- No hidden layer
- Direct mapping: input → output
Mathematically, it behaves like logistic regression.
🔹 2. Forward Propagation
The model computes:
Where:
- → input matrix
- → weight vector
- → bias
- → predicted output
🔹 3. Sigmoid Activation Function
Properties:
- Output between 0 and 1
- Suitable for binary classification
Derivative:
🔹 4. Loss Function (Mean Squared Error)
🔹 5. Backpropagation (Derivation)
We compute gradient of loss w.r.t weights.
Using chain rule:
Step-by-step:
✅ Final Gradient:
🔹 6. Update Rules
Weights:
Bias:
👉 = learning rate
📊 Dataset (OR Gate)
| x1 | x2 | y |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
💻 Python Program
📈 Outputs
🔍 Observations
- Loss decreases over epochs
- Model predicts correctly
- Decision boundary is a straight line
Result
- The neural network successfully classifies OR data
- A linear boundary separates the classes


Comments
Post a Comment