Implementation of XOR Problem using Neural Network in Keras
Experiment
Implementation of XOR Problem using Neural Network in Keras
🎯 Objective
- To implement a neural network using Keras
- To solve the XOR classification problem
- To visualize the decision boundary
- To understand forward propagation and learning behavior
🧠 Theory
🔹 1. XOR Problem
XOR (Exclusive OR) produces output 1 when inputs are different:
| x1 | x2 | y |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
👉 XOR is not linearly separable, meaning it cannot be solved using a single straight line.
🔹 2. Neural Network Requirement
To solve XOR:
- A hidden layer is required
- The network learns non-linear decision boundaries
🔹 3. Model Architecture
- Input Layer → 2 neurons
- Hidden Layer → 4 neurons
- Output Layer → 1 neuron
🔹 4. Activation Functions
-
Hidden layer →
tanh(captures non-linearity well) -
Output layer →
sigmoid(binary output)
🔹 5. Loss Function
- Binary Crossentropy:
🔹 6. Optimizer
-
Adam optimizer:
- Adaptive learning rate
- Efficient training
🔹 7. Keras Input Layer
Modern Keras requires an explicit input definition:
👉 Avoids warnings and improves model clarity.
💻 Program ( Keras Implementation)
📈 Loss Curve Visualization
🌈 Decision Boundary Visualization
🔍 Observations
- Loss decreases over epochs
- Model learns XOR correctly
- Decision boundary is non-linear (curved regions)
Result
- Neural network successfully classifies XOR inputs
- Visualization confirms non-linear separation


Comments
Post a Comment