INDIRA GANDHI DELHI TECHNICAL
UNIVERSITY FOR WOMEN
PRACTICAL FILE
RECENT TRENDS IN ARTIFICIAL INTELLIGENCE
(BAI 418)
BACHELOR OF TECHNOLOGY IN ELECTRONICS AND COMMUNICATION
ENGINEERING- ARTIFICIAL INTELLIGENCE (2021- 25)
SUBMITTED BY
SUBMITTED TO Name- Simone Singh
Prof. Nidhi Goel Enroll. No.- 06701182021
Class- ECE-AI (1)
Semester- VIII SEMESTER
INDEX
S.NO EXPERIMENT DATE
1. a) Design a single unit perceptron for classification of a linearly 22.01.25
separable binary dataset without using pre-defined models. Use the
Perceptron() from sklearn. b) Identify the problem with single unit
Perceptron. Classify using Or-, And- and Xor-ed data and analyze
the result.
2. To Build an Artificial Neural Network by implementing the 05.02.2025
Backpropagation Algorithm and test the same using
appropriate data sets. Vary the activation functions used and
compare the results.
3. To build a deep feedforward ANN (with at least 4 hidden layers) using the 26.02.2025
Backpropagation algorithm and test it using appropriate datasets.
4. To design and implement a Deep Feedforward Neural Network (DFNN) 19.03.2025
for classifying image datasets and analyze the accuracy variation with
respect to the number of training epochs using the MNIST and CIFAR-
10 datasets.
5. To design and implement a CNN model (with 2+ layers of convolutions) 09.04.2025
to classify multi category image datasets. Use the concept of padding
and Batch Normalization while designing the CNN model. Record the
accuracy corresponding to the number of epochs. Use the Fashion
MNIST/MNIST/CIFAR10 datasets
EXPERIMENT- 1
OBJETIVE:
a) Design a single unit perceptron for classification of a linearly separable binary dataset without using
pre-defined models. Use the Perceptron() from sklearn.
b) Identify the problem with single unit Perceptron. Classify using Or-, And- and Xor-ed data and
analyze the result
REQUIREMENTS:
Python
Jupyter notebook/ Google Colab
NumPy
Matplotlib (for visualization)
Scikit-learn
THEORY:
A perceptron is the simplest type of feedforward neural network, consisting of a single neuron. It applies a
weighted sum and passes it through a step function to decide the output. It can only solve linearly
separable problems.
Linearly separable means a straight line (in 2D) or a hyperplane (in higher dimensions) can separate the
data into classes.
The Perceptron from sklearn implements a linear classifier using SGD. It cannot classify non-linear
problems like XOR because there's no straight line that can separate the XOR outputs.
Analysis:
OR and AND are linearly separable – the perceptron works perfectly.
XOR is not linearly separable – perceptron fails.
This proves the limitation: Single-layer perceptrons cannot solve non-linear problems. You need
multi-layer perceptrons (MLPs) for that.
CODE:
a)
b)
OUTPUT:
a) The model correctly classifies all inputs for the OR gate since it is linearly separable.
b)
EXPERIMENT -2
OBJECTIVE: To Build an Artificial Neural Network by implementing the Backpropagation Algorithm and
test the same using appropriate data sets. Vary the activation
functions used and compare the results.
REQUIREMENTS: Google Colab Software
THEORY:
An ANN is a machine learning model inspired by the human brain. It consists of
layers of interconnected neurons. Each neuron processes input data and passes it
through an activation function to produce an output.
Back propagation is the learning algorithm used to train ANNs. It calculates the
Gradient of the loss function with respect to weights using the chain rule and
updates the weights to minimize prediction error.
Steps Involved:
1. Forward Propagation – Pass input through the network to get predictions.
2. Loss Calculation – Compare predicted output with actual output using a loss function (e.g., cross-
entropy).
3. Backward Propagation – Compute gradients of the loss w.r.t. weights and biases.
4. Update Weights – Use gradient descent to update weights.
Activation Functions
Activation functions introduce non-linearity into the network, allowing it to learn
complex patterns. Different activation functions affect learning differently.
Common Activation Functions:
Activation Formula Characteristics
Sigmoid 1 / (1 + e^(-x)) Output between 0 and 1
ReLU max(0, x) Output is 0 for x<0, x for
x>=0
Tanh (e^x - e^(-x)) / (e^x Output between -1 and 1
+ e^(-x))
CODE:
OUTPUT:
EXPERIMENT- III
OBJECTIVE:
To build a deep feedforward ANN (with at least 4 hidden layers) using the Backpropagation algorithm and
test it using appropriate datasets.
REQUIREMENTS:
Python 3.x
TensorFlow or PyTorch
Dataset (e.g., MNIST or tabular data)
matplotlib, numpy
THEORY:
A Deep Feedforward Neural Network (also known as Multi-Layer Perceptron, MLP) is a type of ANN
where data flows only in one direction—from input to output. By increasing the number of hidden layers, the
network can learn more complex patterns and relationships.With ≥4 layers, the network is capable of
performing deep learning tasks, and training is done via backpropagation. Deeper models require
regularization to prevent overfitting and may benefit from techniques like Dropout or Batch Normalization.
CODE:
Output-
EXPERIMENT- IV
OBJECTIVE: To design and implement a Deep Feedforward Neural Network (DFNN) for
classifying image datasets and analyze the accuracy variation with respect to the number of training
epochs using the MNIST and CIFAR-10 datasets.
REQUIREMENTS:
Python 3.x
Jupyter Notebook / Google Colab
TensorFlow or PyTorch (Deep Learning Framework)
NumPy
Matplotlib
Scikit-learn (optional, for metrics)
THEORY:
A Deep Feedforward Neural Network (DFNN), also known as a Multilayer Perceptron
(MLP), is a type of artificial neural network where connections between the nodes do
not form a cycle. It is composed of:
Input layer: Accepts the image pixels as input.
Hidden layers: Apply nonlinear transformations to extract high-level features.
Output layer: Produces classification predictions.
Unlike Convolutional Neural Networks (CNNs), DFNNs do not exploit spatial structure, making them
less effective for image data unless the image is flattened. Still, DFNNs are good for demonstrating
basic deep learning concepts.
Datasets:
MNIST: Contains 70,000 grayscale images of handwritten digits (0–9), size 28×28 pixels.
CIFAR-10: Contains 60,000 color images of size 32×32 pixels across 10 classes (airplane,
automobile, bird, etc.).
CODE:
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Flatten
from tensorflow.keras.datasets import mnist, cifar10
import matplotlib.pyplot as plt
import numpy as np
# Choose dataset: 'mnist' or 'cifar10'
dataset_choice = 'mnist' # Change to 'cifar10' for the CIFAR-10
dataset
if dataset_choice == 'mnist':
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
input_shape = 784
else:
(x_train, y_train), (x_test, y_test) = cifar10.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
x_train = x_train.reshape(-1, 32*32*3)
x_test = x_test.reshape(-1, 32*32*3)
y_train = y_train.flatten()
y_test = y_test.flatten()
input_shape = 32*32*3
# Flatten MNIST data if necessary
if dataset_choice == 'mnist':
x_train = x_train.reshape(-1, 28*28)
x_test = x_test.reshape(-1, 28*28)
# Build the Deep Feedforward Neural Network
model = Sequential([
Dense(512, activation='relu', input_shape=(input_shape,)),
Dense(256, activation='relu'),
Dense(10, activation='softmax') # 10 output classes
])
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
# Track accuracy over multiple epochs
epochs = 20
history = model.fit(x_train, y_train, epochs=epochs,
validation_data=(x_test, y_test), verbose=2)
# Plot accuracy over epochs
plt.plot(history.history['accuracy'], label='Training Accuracy')
plt.plot(history.history['val_accuracy'], label='Validation Accuracy')
plt.xlabel("Epochs")
plt.ylabel("Accuracy")
plt.title(f"DFNN Accuracy over Epochs - {dataset_choice.upper()}
Dataset")
plt.legend()
plt.grid(True)
plt.show()
OUTPUT
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-
datasets/mnist.npz
11490434/11490434 ━━━━━━━━━━━━━━━━━━━━ 1s 0us/step
/usr/local/lib/python3.11/dist-packages/keras/src/layers/core/dense.py:87:
UserWarning: Do not pass an `input_shape`/`input_dim` argument to a layer.
When using Sequential models, prefer using an `Input(shape)` object as the
first layer in the model instead.
super().__init__(activity_regularizer=activity_regularizer, **kwargs)
Epoch 1/20
1875/1875 - 20s - 11ms/step - accuracy: 0.9432 - loss: 0.1860 -
val_accuracy: 0.9673 - val_loss: 0.1070
Epoch 2/20
1875/1875 - 19s - 10ms/step - accuracy: 0.9760 - loss: 0.0788 -
val_accuracy: 0.9729 - val_loss: 0.0874
Epoch 3/20
1875/1875 - 22s - 12ms/step - accuracy: 0.9820 - loss: 0.0561 -
val_accuracy: 0.9753 - val_loss: 0.0798
Epoch 4/20
1875/1875 - 16s - 9ms/step - accuracy: 0.9871 - loss: 0.0403 -
val_accuracy: 0.9750 - val_loss: 0.0874
Epoch 5/20
1875/1875 - 21s - 11ms/step - accuracy: 0.9892 - loss: 0.0340 -
val_accuracy: 0.9802 - val_loss: 0.0774
Epoch 6/20
1875/1875 - 16s - 9ms/step - accuracy: 0.9915 - loss: 0.0255 -
val_accuracy: 0.9803 - val_loss: 0.0795
Epoch 7/20
1875/1875 - 17s - 9ms/step - accuracy: 0.9913 - loss: 0.0270 -
val_accuracy: 0.9815 - val_loss: 0.0762
Epoch 8/20
1875/1875 - 17s - 9ms/step - accuracy: 0.9939 - loss: 0.0190 -
val_accuracy: 0.9769 - val_loss: 0.1015
Epoch 9/20
1875/1875 - 16s - 9ms/step - accuracy: 0.9930 - loss: 0.0217 -
val_accuracy: 0.9831 - val_loss: 0.0704
Epoch 10/20
1875/1875 - 23s - 12ms/step - accuracy: 0.9950 - loss: 0.0157 -
val_accuracy: 0.9822 - val_loss: 0.0866
Epoch 11/20
1875/1875 - 18s - 10ms/step - accuracy: 0.9952 - loss: 0.0151 -
val_accuracy: 0.9839 - val_loss: 0.0847
Epoch 12/20
1875/1875 - 21s - 11ms/step - accuracy: 0.9946 - loss: 0.0189 -
val_accuracy: 0.9827 - val_loss: 0.0877
Epoch 13/20
1875/1875 - 17s - 9ms/step - accuracy: 0.9962 - loss: 0.0116 -
val_accuracy: 0.9793 - val_loss: 0.1150
Epoch 14/20
1875/1875 - 17s - 9ms/step - accuracy: 0.9962 - loss: 0.0118 -
val_accuracy: 0.9781 - val_loss: 0.1233
Epoch 15/20
1875/1875 - 20s - 11ms/step - accuracy: 0.9958 - loss: 0.0147 -
val_accuracy: 0.9809 - val_loss: 0.1216
Epoch 16/20
1875/1875 - 22s - 12ms/step - accuracy: 0.9959 - loss: 0.0152 -
val_accuracy: 0.9812 - val_loss: 0.1251
Epoch 17/20
1875/1875 - 16s - 9ms/step - accuracy: 0.9965 - loss: 0.0120 -
val_accuracy: 0.9778 - val_loss: 0.1529
Epoch 18/20
1875/1875 - 24s - 13ms/step - accuracy: 0.9970 - loss: 0.0113 -
val_accuracy: 0.9803 - val_loss: 0.1283
Epoch 19/20
1875/1875 - 17s - 9ms/step - accuracy: 0.9968 - loss: 0.0119 -
val_accuracy: 0.9803 - val_loss: 0.1354
Epoch 20/20
1875/1875 - 17s - 9ms/step - accuracy: 0.9969 - loss: 0.0121 -
val_accuracy: 0.9798 - val_loss: 0.1419
EXPERIMENT V
OBJECTIVE:
To design and implement a CNN model (with 2+ layers of convolutions) to classify multi category
image datasets. Use the concept of padding and Batch Normalization while designing the CNN
model. Record the accuracy corresponding to the number of epochs. Use the Fashion
MNIST/MNIST/CIFAR10 datasets
REQUIREMENTS
Python (3.x)
Jupyter Notebook / Google Colab
TensorFlow / Keras library
NumPy, Matplotlib
CIFAR-10 dataset
THEORY
Convolutional Neural Networks (CNNs) are a type of deep learning architecture widely used for
image classification tasks. They are especially effective for visual data as they automatically learn
spatial hierarchies of features through convolutional and pooling operations.
In this experiment, we use the Fashion MNIST dataset, which is a drop-in replacement for the original
MNIST dataset. It consists of 70,000 grayscale images of 10 fashion categories (such as T-shirts,
trousers, sandals, etc.), each of size 28x28 pixels. This dataset is more complex than digit
classification, making it a good benchmark for testing image classification models.
Key components used in our CNN architecture:
Convolutional Layers: These apply filters to the input image to detect features such as edges,
textures, and patterns. We use multiple convolutional layers to extract hierarchical features
from the images.
Padding ('same'): Padding ensures that the output size remains the same as the input size after
convolution. This helps preserve edge information and improves performance, especially for
small-sized images like 28x28.
Batch Normalization: This technique normalizes the output of each convolutional layer to
stabilize and accelerate training. It also helps prevent overfitting by adding a slight
regularization effect.
Max Pooling: This reduces the spatial dimensions of the feature maps and helps in reducing
computational load while retaining important features.
Dropout: A regularization method that randomly deactivates a portion of neurons during
training to prevent overfitting.
The model is trained for several epochs, and the accuracy is recorded after each epoch to analyze how
well the model learns over time. Both training and validation accuracies are used to evaluate
performance and generalization.
CODE
OUTPUT