SlideShare a Scribd company logo
https://www.analyticsvidhya.com/blog/2017/09/creating-
visualizing-neural-network-in-r/
The Basics of Neural Network
 A neural network is a model characterized by an activation function, which is used by
interconnected information processing units to transform input into output.
 A neural network has always been compared to human nervous system. Information in
passed through interconnected units analogous to information passage through neurons in
humans.
 The first layer of the neural network receives the raw input, processes it and passes the
processed information to the hidden layers. The hidden layer passes the information to
the last layer, which produces the output.
 The advantage of neural network is that it is adaptive in nature. It learns from the
information provided, i.e. trains itself from the data, which has a known outcome and
optimizes its weights for a better prediction in situations with unknown outcome.
 A perceptron, viz. single layer neural network, is the most basic form of a neural
network. A perceptron receives multidimensional input and processes it using a weighted
summation and an activation function.
 It is trained using a labeled data and learning algorithm that optimize the weights in the
summation processor. A major limitation of preceptor model is its inability to deal with
non-linearity.
 A multilayered neural network overcomes this limitation and helps solve non-linear
problems. The input layer connects with hidden layer, which in turn connects to the
output layer. The connections are weighted and weights are optimized using a learning
rule.
 There are many learning rules that are used with neural network:
a) least mean square;
b) gradient descent;
c) newton’s rule;
d) conjugate gradient etc.
 The learning rules can be used in conjunction with backpropgation error method. The
learning rule is used to calculate the error at the output unit. This error is backpropagated
to all the units such that the error at each unit is proportional to the contribution of that
unit towards total error at the output unit. The errors at each unit are then used to
optimize the weight at each connection.
 Figure 1 displays the structure of a simple neural network model for better understanding.
Fitting Neural Network in R
 Now we will fit a neural network model in R. In this article, we use a subset of cereal
dataset shared by Carnegie Mellon University (CMU). The details of the dataset are on
the following link: http://lib.stat.cmu.edu/DASL/Datafiles/Cereals.html.
 The objective is to predict rating of the cereals variables such as calories, proteins, fat
etc.
 The R script is provided side by side and is commented for better understanding of the
user. . The data is in .csv format and can be downloaded by clicking: cereals.
 Please set working directory in R using setwd( ) function, and keep cereal.csv in the
working directory.
 We use rating as the dependent variable and calories, proteins, fat, sodium and fiber as
the independent variables.
 We divide the data into training and test set. Training set is used to find the relationship
between dependent and independent variables while the test set assesses the performance
of the model.
 We use 60% of the dataset as 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.
 We have used set.seed( ) to generate same random sample every time and maintain
consistency.
 We will use the index variable while fitting neural network to create training and test data
sets.
The R script is as follows:
## Creating index variable
# Read the Data
data = read.csv("cereals.csv", header=T)
# Random sampling
samplesize = 0.60 * nrow(data)
set.seed(80)
index = sample( seq_len ( nrow ( data ) ), size = samplesize )
# Create training and test set
datatrain = data[ index, ]
datatest = data[ -index, ]
 Now we fit a neural network on our data. We use neuralnet library for the analysis. The
first step is to scale the cereal dataset.
 The scaling of data is essential because otherwise a variable may have large impact on
the prediction variable only because of its scale. Using unscaled 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. Unlike Z-score normalization and median and MAD method, the min-max
method retains the original distribution of the variables. We use min-max normalization
to scale the data. The R script for scaling the data is as follows.

More Related Content

PPTX
Neural network in R by Aman Chauhan
PPTX
Artificial neural network
PDF
Artificial neural network
PPTX
Soft computing
PPTX
Dataminng
PPTX
Neural network
PDF
Neural network image recognition
PDF
Performance Comparision of Machine Learning Algorithms
Neural network in R by Aman Chauhan
Artificial neural network
Artificial neural network
Soft computing
Dataminng
Neural network
Neural network image recognition
Performance Comparision of Machine Learning Algorithms

What's hot (20)

PPTX
Operating system
POTX
SoftComputing6
DOCX
SVM & MLP on Matlab program
PPTX
Presentation_Malware Analysis.pptx
PDF
Data Science - Part VIII - Artifical Neural Network
PPTX
AI IEEE
PDF
Face Recognition Using Neural Networks
PPTX
Meta-Learning Presentation
PDF
How to create your own artificial neural networks
PPTX
Short Story Submission on Meta Learning
PPTX
Kcc201728apr2017 170828235330
PDF
International Refereed Journal of Engineering and Science (IRJES)
PPTX
Heart disease classification
PDF
Machine learning - AI
PPTX
Impact of Learning Functions on Prediction of Stock Data
PDF
Meta learning with memory augmented neural network
PPT
High dimesional data (FAST clustering ALG) PPT
DOCX
Student intervention detection using deep learning technique
DOCX
Student intervention detection using deep learning technique
PDF
Introduction to MAML (Model Agnostic Meta Learning) with Discussions
Operating system
SoftComputing6
SVM & MLP on Matlab program
Presentation_Malware Analysis.pptx
Data Science - Part VIII - Artifical Neural Network
AI IEEE
Face Recognition Using Neural Networks
Meta-Learning Presentation
How to create your own artificial neural networks
Short Story Submission on Meta Learning
Kcc201728apr2017 170828235330
International Refereed Journal of Engineering and Science (IRJES)
Heart disease classification
Machine learning - AI
Impact of Learning Functions on Prediction of Stock Data
Meta learning with memory augmented neural network
High dimesional data (FAST clustering ALG) PPT
Student intervention detection using deep learning technique
Student intervention detection using deep learning technique
Introduction to MAML (Model Agnostic Meta Learning) with Discussions
Ad

Similar to Neural basics (20)

PDF
Neural network based numerical digits recognization using nnt in matlab
DOCX
artificial-neural-network-seminar-report.docx
PPTX
Sachpazis: Demystifying Neural Networks: A Comprehensive Guide
PPTX
minimalist-business-slides.v dsgjnejgndjgnejgnjgnrjhgdjgngdngtpptx
PDF
Deep Learning Study _ FInalwithCNN_RNN_LSTM_GRU.pdf
PDF
Feed forward neural network for sine
PDF
bbbPaper
PDF
Analysis and Comparison Study of Data Mining Algorithms Using Rapid Miner
PDF
ANALYSIS AND COMPARISON STUDY OF DATA MINING ALGORITHMS USING RAPIDMINER
PDF
Comparative Study of Pre-Trained Neural Network Models in Detection of Glaucoma
PDF
Electricity Demand Forecasting Using ANN
PPTX
Introduction Of Artificial neural network
PPTX
2. NEURAL NETWORKS USING GENETIC ALGORITHMS.pptx
PDF
IRJET-Breast Cancer Detection using Convolution Neural Network
PDF
Open CV Implementation of Object Recognition Using Artificial Neural Networks
PDF
IRJET- Hybrid Architecture of Heart Disease Prediction System using Genetic N...
DOCX
Research Paper - Vaibhav
PPTX
House price prediction
PDF
AN IMPROVED METHOD FOR IDENTIFYING WELL-TEST INTERPRETATION MODEL BASED ON AG...
PPTX
Deeplearning for Computer Vision PPT with
Neural network based numerical digits recognization using nnt in matlab
artificial-neural-network-seminar-report.docx
Sachpazis: Demystifying Neural Networks: A Comprehensive Guide
minimalist-business-slides.v dsgjnejgndjgnejgnjgnrjhgdjgngdngtpptx
Deep Learning Study _ FInalwithCNN_RNN_LSTM_GRU.pdf
Feed forward neural network for sine
bbbPaper
Analysis and Comparison Study of Data Mining Algorithms Using Rapid Miner
ANALYSIS AND COMPARISON STUDY OF DATA MINING ALGORITHMS USING RAPIDMINER
Comparative Study of Pre-Trained Neural Network Models in Detection of Glaucoma
Electricity Demand Forecasting Using ANN
Introduction Of Artificial neural network
2. NEURAL NETWORKS USING GENETIC ALGORITHMS.pptx
IRJET-Breast Cancer Detection using Convolution Neural Network
Open CV Implementation of Object Recognition Using Artificial Neural Networks
IRJET- Hybrid Architecture of Heart Disease Prediction System using Genetic N...
Research Paper - Vaibhav
House price prediction
AN IMPROVED METHOD FOR IDENTIFYING WELL-TEST INTERPRETATION MODEL BASED ON AG...
Deeplearning for Computer Vision PPT with
Ad

Recently uploaded (20)

PPTX
Internet of Things (IOT) - A guide to understanding
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
web development for engineering and engineering
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
Welding lecture in detail for understanding
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
Well-logging-methods_new................
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
Digital Logic Computer Design lecture notes
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
Geodesy 1.pptx...............................................
PPT
Project quality management in manufacturing
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPTX
OOP with Java - Java Introduction (Basics)
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
Internet of Things (IOT) - A guide to understanding
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
web development for engineering and engineering
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Automation-in-Manufacturing-Chapter-Introduction.pdf
Operating System & Kernel Study Guide-1 - converted.pdf
Welding lecture in detail for understanding
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Well-logging-methods_new................
CYBER-CRIMES AND SECURITY A guide to understanding
Digital Logic Computer Design lecture notes
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Geodesy 1.pptx...............................................
Project quality management in manufacturing
R24 SURVEYING LAB MANUAL for civil enggi
OOP with Java - Java Introduction (Basics)
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS

Neural basics

  • 1. https://www.analyticsvidhya.com/blog/2017/09/creating- visualizing-neural-network-in-r/ The Basics of Neural Network  A neural network is a model characterized by an activation function, which is used by interconnected information processing units to transform input into output.  A neural network has always been compared to human nervous system. Information in passed through interconnected units analogous to information passage through neurons in humans.  The first layer of the neural network receives the raw input, processes it and passes the processed information to the hidden layers. The hidden layer passes the information to the last layer, which produces the output.  The advantage of neural network is that it is adaptive in nature. It learns from the information provided, i.e. trains itself from the data, which has a known outcome and optimizes its weights for a better prediction in situations with unknown outcome.  A perceptron, viz. single layer neural network, is the most basic form of a neural network. A perceptron receives multidimensional input and processes it using a weighted summation and an activation function.  It is trained using a labeled data and learning algorithm that optimize the weights in the summation processor. A major limitation of preceptor model is its inability to deal with non-linearity.  A multilayered neural network overcomes this limitation and helps solve non-linear problems. The input layer connects with hidden layer, which in turn connects to the output layer. The connections are weighted and weights are optimized using a learning rule.  There are many learning rules that are used with neural network: a) least mean square; b) gradient descent; c) newton’s rule; d) conjugate gradient etc.  The learning rules can be used in conjunction with backpropgation error method. The learning rule is used to calculate the error at the output unit. This error is backpropagated to all the units such that the error at each unit is proportional to the contribution of that unit towards total error at the output unit. The errors at each unit are then used to optimize the weight at each connection.  Figure 1 displays the structure of a simple neural network model for better understanding.
  • 2. Fitting Neural Network in R  Now we will fit a neural network model in R. In this article, we use a subset of cereal dataset shared by Carnegie Mellon University (CMU). The details of the dataset are on the following link: http://lib.stat.cmu.edu/DASL/Datafiles/Cereals.html.  The objective is to predict rating of the cereals variables such as calories, proteins, fat etc.  The R script is provided side by side and is commented for better understanding of the user. . The data is in .csv format and can be downloaded by clicking: cereals.  Please set working directory in R using setwd( ) function, and keep cereal.csv in the working directory.  We use rating as the dependent variable and calories, proteins, fat, sodium and fiber as the independent variables.  We divide the data into training and test set. Training set is used to find the relationship between dependent and independent variables while the test set assesses the performance of the model.  We use 60% of the dataset as 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.  We have used set.seed( ) to generate same random sample every time and maintain consistency.  We will use the index variable while fitting neural network to create training and test data sets.
  • 3. The R script is as follows: ## Creating index variable # Read the Data data = read.csv("cereals.csv", header=T) # Random sampling samplesize = 0.60 * nrow(data) set.seed(80) index = sample( seq_len ( nrow ( data ) ), size = samplesize ) # Create training and test set datatrain = data[ index, ] datatest = data[ -index, ]  Now we fit a neural network on our data. We use neuralnet library for the analysis. The first step is to scale the cereal dataset.  The scaling of data is essential because otherwise a variable may have large impact on the prediction variable only because of its scale. Using unscaled 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. Unlike Z-score normalization and median and MAD method, the min-max method retains the original distribution of the variables. We use min-max normalization to scale the data. The R script for scaling the data is as follows.