FACULTY OF SCIENCE AND HUMANITIES
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
VADAPALANI CAMPUS
LAB RECORD
NAME OF THE STUDENT : CH.SAI CHANDU
REGISTER NUMBER : RA2332241040008
NAME OF THE COURSE : MCA/COMPUTER
APPLICATION CLASS & YEAR : I & I Year
SUBJECT CODE : PCA20S02J
SUBJECT NAME : DATA ANALYSIS USING R LAB
APR-2024
DEPARTMENT OF COMPUTER SCIENCE AND APPLICATIONS
FACULTY OF SCIENCE AND HUMANITIES
VADAPALANI CAMPUS
CERTIFICATE
This is to certify that this is a Bonafede record of practical work done by
NAME OF THE STUDENT : CH.SAI CHANDU
REGISTER NUMBER : RA2332241040008
NAME OF THE COURSE : MCA/COMPUTER
APPLICATION CLASS & YEAR : I & I Year
SUBJECT CODE : PCA20S02J
SUBJECT NAME : DATA ANALYSIS USING R LAB
During the Academic Year 2023 -2024 & Submitted for MCA practical examination held on
.
LECTURER INCHARGE HEAD OF THE DEPARTMENT
INTERNAL EXAMINER EXTERNAL EXAMINER
INDEX
S.NO` DATE NAME OF THE PAGE SIGNATURE
EXERCISE NO
INTRODUCTION TO
1 SVM
2 CLASSIFICATION OF
SVM
3 USAGE OF SVM
4 IMPLEMENTATION
OF SVM
ADVANTAGES OF
5 SVM
6 DISADVANTAGES
OF SVM
7 CONCLUSION
NEURAL NETWORKS
NEURAL NETWORKS
Neural networks are an essential part of machine learning (ML)
and artificial intelligence (AI) systems because they imitate the structure and
operations of the human brain, which allows them to comprehend complex data
and come to conclusions or predictions.
• INTRODUCTION TO NEURAL NETWORKS:
Neural networks are computational models inspired by the
structure and function of the human brain. They consist of interconnected nodes,
or neurons, organized in layers. Information flows through the network, with
each neuron processing input data and passing it on to the next layer. Through a
process called training, neural networks learn to recognize patterns and make
predictions from data. They have become a powerful tool in various fields,
including image and speech recognition, natural language processing, and
predictive analytics. Certainly! Neural networks, also known as artificial neural
networks (ANNs), are a type of machine learning model composed of
interconnected nodes called neurons. These neurons are organized in layers: an
input layer, one or more hidden layers, and an output layer.
Each neuron receives input signals, processes them using an
activation function, and passes the result to neurons in the next layer. During
training, the network adjusts the weights assigned to connections between
neurons to minimize the difference between its predictions and the actual
outcomes. This process, known as backpropagation, allows the network to learn
from labeled data and improve its performance over time. Neural networks are
highly flexible and can learn complex patterns from large amounts of data,
making them well-suited for tasks such as image and speech recognition, natural
language processing, and predictive analytics. They have fueled significant
advancements in artificial intelligence and are widely used across various
industries.
HISTORY AND TIMELINE OF NEURAL NETWORKS
The history of neural networks spans several decades and has
seen considerable advancements. The following examines the important
milestones and developments in the history of neural networks:
1940s. In 1943, mathematicians Warren McCulloch and
Walter Pitts built a circuitry system that ran simple algorithms and was intended
to approximate the functioning of the human brain.
1950s. In 1958, Frank Rosenblatt, an American psychologist
who's also considered the father of deep learning, created the perceptron, a form
of artificial neural network capable of learning and making judgments by
modifying its weights. The perceptron featured a single layer of computing
units and could handle problems that were linearly separate.
1970s. Paul Werbos, an American scientist, developed the
backpropagation method, which facilitated the training of multilayer neural
networks. It made deep learning possible by enabling weights to be adjusted
across the network based on the error calculated at the output layer.
1980s. Cognitive psychologist and computer scientist
Geoffrey Hinton, along with computer scientist Yann LeCun, and a group of
fellow researchers began investigating the concept of connectionism, which
emphasizes the idea that cognitive processes emerge through interconnected
networks of simple processing units. This period paved the way for modern
neural networks and deep learning.
1990s. Jürgen Schmidhuberand Sepp Hochreiter, both
computer scientists from Germany, proposed the Long Short-Term Memory
recurrent neural network framework in 1997.
2000s. Geoffrey Hinton and his colleagues pioneered RBMs,
a sort of generative artificial neural network that enables unsupervised
learning. RBMs opened the path for deep belief networks and deep learning
algorithms.
It wasn't until around 2010 that research in neural networks
picked up great speed. The big data trend, where companies amass vast troves of
data and parallel computing gave data scientists the training data and computing
resources needed to run complex artificial neural networks. In 2012, a neural
network named AlexNet won the ImageNet Large Scale Visual Recognition
competition, an image classification challenge. Since then, interest in artificial
neural networks has soared and technology has continued to improve.
• HOW DOES NEURAL NETWORK WORKS:
Take into consideration an email classification neural
network. Features including email content, sender information, and subject are
taken in by the input layer. These inputs go through hidden layers after being
multiplied by modified weights. The network gains the ability to identify patterns
that indicate whether or not an email is spam through training. Using a binary
activation function, the output layer determines if the email is spam (1) or not (0).
Neural networks are useful in real-world applications such as email filtering, as
demonstrated by the network's ability to discern between valid and spam emails as
iteratively refines its weights through backpropagation.
WORKING OF NEURAL NETWORKS
Complex systems called neural networks imitate some aspects
of how the human brain operates. It consists of three layers: an input layer, one or
more hidden layers, and an output layer formed of linked layers of artificial
neurons. The terms "forward propagation" and "backpropagation" refer to the two
phases of the fundamental operation.
FORWARD PROPAGATION
Input Layer: Nodes on the network that receive input data represent each feature
in the input layer.
Weights and Connections: Each neural connection's weight reveals the strength
of
that link. They swap out these weights during training.
Hidden Layers: In order to process inputs, each hidden layer neuron
multiplies them by weights, adds them together, and then sends them through an
activation function. This introduces non-linearity, which makes it possible for the
network to identify complex patterns.
Output: After the procedure is repeated until the output layer is reached, the
final result is generated.
BACKWARD PROPAGATION
Backpropagation Loss Calculation: The difference between the network's
output and the actual goal values is calculated using a loss function. The Mean
Squared Error (MSE) is frequently utilized as the cost function for regression
problems.
Loss Mechanism:
Gradient Descent: The network then applies gradient descent to lessen the loss.
Weights are adjusted according to the derivative of the loss with regard to each
weight in order to reduce the inaccuracy.
Weight adjustment: By using this iterative technique, also known as
backpropagation, backward over the network, the weights are modified at each
link.
TYPES OF NEURAL NETWORKS:
Feedforward Neteworks: A feedforward neural network is a simple artificial
neural network architecture in which data moves from input to output in a single
direction. It has input, hidden, and output layers; feedback loops are absent. Its
straightforward architecture makes it appropriate for a number of applications,
such as regression and pattern recognition.
Multilayer Perceptron (MLP): MLP is a type of feedforward neural network
with three or more layers, including an input layer, one or more hidden layers, and
an output layer. It uses nonlinear activation functions.
Convolutional Neural Network (CNN): A Convolutional Neural Network (CNN)
is a specialized artificial neural network designed for image processing. It employs
convolutional layers to automatically learn hierarchical features from input images,
enabling effective image recognition and classification. CNNs have revolutionized
computer vision and are pivotal in tasks like object detection and image analysis.
Recurrent Neural Network (RNN): An artificial neural network type intended
for sequential data processing is called a Recurrent Neural Network (RNN). It is
appropriate for applications where contextual dependencies are critical, such as
time series prediction and natural language processing, since it makes use of
feedback loops, which enable information to survive within the network.
Long Short-Term Memory (LSTM): LSTM is a type of RNN that is designed to
overcome the vanishing gradient problem in training RNNs. It uses memory cells
and gates to selectively read, write, and erase information.
IMPLEMENTATION OF NEURAL NETWORKS IN R
We will learn to create neural networks with popular R packages neuralnet and
Keras.
In the first example, we will create a simple neural network with minimum effort,
and in the second example, we will tackle a more advanced problem using the
Keras package.
Let's set up the R environment by downloading essential libraries and
dependencies.
install.packages(c('neuralnet','keras','tensorflow'),dependencies = T)
Simple Neural Network implementation in R: In this first example, we will be
using built-in R data iris and solve multi-classification problems with a simple
neural network.
We will start by importing essential R packages for data manipulation and model
training.
library(tidyverse)
library(neuralnet)
Data Analysis: You can access data by typing `iris` and running it in the R
console. Before training the data, we need to convert character column types into
factors.
iris <- iris %>% mutate_if(is.character, as.factor)
The `summary` function is used for statistical analysis and data distribution.
summary(iris)
Step 1:
Scaling of the data: To set up a neural network to a dataset it is very important
that we ensure a proper scaling of data. The scaling of data is essential because
otherwise, a variable may have a large impact on the prediction variable only
because of its scale. Using unscaled data may lead to meaningless results. The
common techniques to scale data are min-max normalization, Z-score
normalization, median and MAD, and tan-h estimators. The min-max
normalization transforms the data into a common range, thus removing the scaling
effect from all the variables. Here we are using min-max normalization for scaling
data.
# Draw a histogram for gre data
hist(data$gre)
OUTPUT
From the above histogram of gre we can see that the gre varies from 200 to 800.
We invoke the following function to normalize our data:
normalize <- function(x) {
return ((x - min(x)) / (max(x) - min(x)))
}
# Min-Max Normalization
data$gre <- (data$gre - min(data$gre)) / (max(data$gre) - min(data$gre))
hist(data$gre)
From the
above representation we can see that gre data is scaled in the range of 0 to 1.
Similar we do for gpa and rank.
# Min-
Max Normalization
data$gpa <- (data$gpa - min(data$gpa)) / (max(data$gpa) -
min(data$gpa)) hist(data$gpa)
data$rank <- (data$rank - min(data$rank)) / (max(data$rank) -
min(data$rank))
hist(data$rank)
It can be
seen from the above two histogram representation that gpa and rank are also scaled
in the range of 0 to 1. The scaled data is used to fit the neural network.
Step 2:
Sampling of the data: Now divide the data into a training set and test set. The
training set is used to find the relationship between dependent and independent
variables while the test set analyses the performance of the model. We use 60% of
the dataset as a training set. The assignment of the data to training and test set is
done using random sampling. We perform random sampling on R using sample()
function. Use set.seed()to generate same random sample every time and maintain
consistency. Use the index variable while fitting neural network to create training
and test data sets. The R script is as follows:
set.seed(222)
inp <- sample(2, nrow(data), replace = TRUE, prob = c(0.7,
0.3)) training_data <- data[inp==1, ]
test_data <- data[inp==2, ]
Step 3:
Fitting a Neural Network: Now fit a neural network on our data. We use
neuralnet library for the same. neuralnet() function helps us to establish a neural
network for our data. The neuralnet() function we are using here has the following
syntax.
Syntax:
neuralnet(formula, data, hidden = 1, stepmax = 1e+05, rep = 1, lifesign =
“none”, algorithm = “rprop+”, err.fct = “sse”, linear.output = TRUE)
here's a simple example of how you can implement a neural network in R using
the neuralnet package:
# Install and load the neuralnet package if you haven't
already # install.packages("neuralnet")
library(neuralnet)
# Generate some sample
data set.seed(123)
n <- 1000
x1 <- runif(n, 0, 10)
x2 <- runif(n, 0, 10)
y <- x1^2 + x2^2 +
rnorm(n)
# Combine predictors into a data
frame data <- data.frame(x1, x2, y)
# Split data into training and testing
sets train_indices <- sample(1:n, 0.8 *
n)
train_data <- data[train_indices, ]
test_data <- data[-train_indices, ]
# Define the neural network
architecture
# In this example, we have 2 input neurons, 5 hidden neurons, and 1 output
neuron # The hidden layer uses a logistic activation function by default
nn <- neuralnet(y ~ x1 + x2, data = train_data, hidden = 5)
# Make predictions on the testing set
predicted <- compute(nn, test_data[, c("x1", "x2")])$net.result
# Calculate Mean Squared Error (MSE) to evaluate the
model mse <- mean((predicted - test_data$y)^2)
cat("Mean Squared Error:", mse, "\n")
WHAT ARE NEURAL NETWORK USED FOR:
Numerous sectors have found applications for neural networks, including
the following:
• Medical picture classification for medical diagnosis
• Behavioral data analysis and social network filtering for targeted
marketing
• financial forecasts using financial instrument historical data
processing
• Forecasting electrical load and energy consumption
• Procedure and quality assurance
• Identification of chemical compounds
APPLICATIONS OF NEURAL NETWORKS :
Neural networks have a wide range of applications across various industries,
including:
• Computer vision: object detection, image classification, facial recognition.
• Natural language processing: language translation, sentiment analysis,
chatbots.
• Healthcare: disease diagnosis, drug discovery, medical image analysis.
• Finance: stock market prediction, fraud detection, algorithmic trading.
• Automotive: autonomous driving, vehicle detection, predictive
maintenance.
ADVANTAGES OF NEURAL NETWORKS
Neural networks are widely used in many different applications because of their
many benefits:
• Adaptability: Neural networks are useful for activities where the link
between inputs and outputs is complex or not well defined because they can
adapt to new situations and learn from data.
• Pattern Recognition: Their proficiency in pattern recognition renders them
efficacious in tasks like as audio and image identification, natural language
processing, and other intricate data patterns.
• Parallel Processing: Because neural networks are capable of parallel
processing by nature, they can process numerous jobs at once, which speeds
up and improves the efficiency of computations.
• Non-Linearity: Neural networks are able to model and
comprehend
complicated relationships in data by virtue of the non-linear activation
functions found in neurons, which overcome the drawbacks of linear
models.
DISADVANTAGES OF NEURAL NETWORKS
Neural networks, while powerful, are not without drawbacks and difficulties:
• Computational Intensity: Large neural network training can be a laborious
and computationally demanding process that demands a lot of computing
power.
• Black box Nature: As “black box” models, neural networks pose a problem
in important applications since it is difficult to understand how they make
decisions.
• Overfitting: Overfitting is a phenomenon in which neural networks commit
training material to memory rather than identifying patterns in the data.
Although regularization approaches help to alleviate this, the problem still
exists.
• Need for Large datasets: For efficient training, neural networks frequently
need sizable, labeled datasets; otherwise, their performance may suffer from
incomplete or skewed data.
OBSTACLES AND PROSPECTS:
Not withstanding their achievements, neural networks encounter obstacles such
overfitting, interpretability, and resilience against hostile assaults. Prospective
avenues for investigation encompass enhancing the effectiveness,
comprehensibility, and expandability of neural networks, in addition to
investigating innovative structures and learning algorithms.
Finally, neural networks are strong instruments for resolving intricate issues
across a wide range of fields, and their further development is likely to have a
significant impact on machine learning and artificial intelligence in the future.
CONCLUSION:
In conclusion, neural networks are powerful tools for solving complex problems
in various domains, and their continued advancement holds great promise for
the future of AI and machine learning.