Experiment 1
Experiment 1
Aim:
To design and implement a Multilayer Perceptron (MLP) for classifying handwritten digits from the MNIST dataset
using TensorFlow and Keras.
Objective:
● Understand the concept of Multilayer Perceptron (MLP).
● Learn how to use TensorFlow and Keras to build and train an MLP model.
● Perform digit classification on the MNIST dataset.
● Evaluate model performance using accuracy metrics.
Theory:
Multilayer Perceptron (MLP) is a type of artificial neural network (ANN) that consists of multiple layers:
The MNIST dataset consists of 70,000 grayscale images of handwritten digits (0-9), with 60,000 for training and
10,000 for testing.
Program:
# Import necessary libraries
import tensorflow as tf
from tensorflow import keras
import numpy as np
import matplotlib.pyplot as plt
Explanation:
1. Import Libraries: We import TensorFlow, Keras, and other required libraries.
2. Load MNIST Dataset: The dataset is loaded and split into training and testing sets.
3. Normalize Data: The pixel values are scaled to [0,1] for better convergence.
4. Define Model:
○ Flatten Layer: Converts 2D images to a 1D array.
○ Dense Layer (128 neurons, ReLU activation): Learns features from input data.
○ Dense Layer (10 neurons, Softmax activation): Outputs probabilities for 10 digit classes.
5. Compile Model:
○ Optimizer: Adam optimizer is used for gradient descent.
○ Loss Function: Sparse Categorical Crossentropy is used for multi-class classification.
○ Metrics: Accuracy is used to measure model performance.
6. Train Model: The model is trained for 5 epochs using the training dataset.
7. Evaluate Model: The model's accuracy is tested on unseen test data.
Conclusion:
The MLP model successfully classifies handwritten digits from the MNIST dataset with high accuracy. The model
can be further improved by tuning hyperparameters or adding more hidden layers.
I will now proceed with Experiment 2. Let me know if you need modifications or additional explanations!