Inspiration for Neural Network comes from psychologist and neurobiologist. They wanted to develop computational analogous to neurons. Hence, computational neural network is also called artificial neural network.

Neural Network (NN) has neurons and layers in its architecture. 3 layers in Neural Network are *Input Layer* , *Hidden Layer* and *Output Layer*. Each of these layers have units or neurons in it.

Simple Neural Network Representation

#### Neural Network - Examples and Applications

Due to complexity of neural network, it has been used less frequently. A number of applications of neural network across industries

**Neural Network in Banking and Financial Sefvices**

*Measuring Credit Risk of New Applicants*: Credit Risk is risk of default by the customers whom a credit facility is approved. Banks and financial institutions build predictive model for assessing credit worthiness of the new applicants. Various techniques are used for building the credit risk scorecard or predictive model. Neural Network is also used for classifying customers into Good and Bad. In this scenario, target variable is binary and type of problem is classification.*Predicting Loan Recovery Rate*: Even after using advanced credit scorecard, there is a default. Once customers are defaulted on their loan repayment, the financial institutions aim to recover as much money as possible (by abiding regulatory and legal rules) from the defaulted customers. The recovery rate ( complement of loss given default) is fraction of outstanding balances recovered from the defaulted customers. Neural Network based non-parametric model is used for forecasting bank recoveries.*Insurance Loss Reserve*: In insurance, estimating future cash reserve requirement is crucial to optimize operations. The cash reserve requirement depends on future claim volumes and claim amount. Artificial Neural Network (ANN) could be used for forecasting future claims.

Neural Network is also used for retail - store segmentation, forecasting aggregate sales volume and predicting responders for loyalty mailing.

#### Neural Network Algorithms

A neural network architecture has input, hidden and output layers and each layer has processing unit(s).

Each of the processing unit has inputs along with their weights (for assigning different level of importance to inputs). The inputs along with weights are aggregated and appropriate transformation (activation function) is applied to the aggregated input.

Based on the sample data, the weights have to be estimated. There are various algorithms to training the network. One of the commonly used neural network algorithm is *Backpropagation*.

Using initial weights, the target state/labels are estimated using the neural network. The estimate labels are compared against target or actual labels. The gap is called Error and the error is back propagated to improve the weights and reduce the error.

#### Neural Network Example

A marketing department of a bank runs various marketing campaigns for cross-selling products, customer retention and customer services. In this blog, we will use Marketing Data sample. In this example, the bank wanted to cross-sell term depoisit product to its customers.

Contacting all customers is costly and does not create good customer experience. So, the bank wanted to build a predictive model which will identify customers who are more likely to respond to term deport cross sell campaign. More details on data preparation for predictive modeling.

It is an example of supervised learning. Target variable: Whether a customer is responding to a cross sell campaign. Independent Variables:

*age* : Age of customer *duration*: Last cotact duration in second *Job Level*: Job Levels

Neural Network(NN) is used for building a predictive model.

#### Neural Network in R

R has at least two packages on neural network. These are **nnet** and **neuralnet** . **nnet** has feed-forward neural networks with a single hidden layer network algorithm implementation.

**neuralnet** has algorithm for backpropagation with many more features.

*neuralnet* function within **neuralnet** package can be used for training the neural network.

Similarly, **nnet** function from **nnet** package could be used for training feed-forward neural networks with a single hidden layer

In this blog, we will focus on simple feed forward neural network. Next blog will focus on backward propagation naural network with many complexities.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
install.packages("neuralnet") install.packages("nnet") library(neuralnet) library(nnet) # Trainin Network s1.nn <- neuralnet(cross.resp~age, data=termCrossSell, hidden = 0, threshold = 0.01, act.fct="tanh" ) # Plot Neural Network plot(s1.nn) |

'

This is the simplest Neural Network example. Only one input layer and one output layer with a single variable. Blue line shows Bias.

We can check the accuracy of the result.

We can calculate predicted response values using trained neural network.

1 2 |
# Train sample creation with 20000 observations testData <- termCrossSell[sample(20000),c('age','cross.resp')] |

Compute the predicted values based on the trained network on the new sample. **compute** function is used.

1 2 3 4 |
# Predicted Response pred.resp <-compute(s1.nn, testData$age) table(testData$cross.resp) |

In the input samples, cross sell response % is 3%. So, top 3% are tagged as 1 in the test data frame.

1 2 3 4 5 6 7 8 9 10 11 |
# Find cut off sort(pred.resp$net.result,decreasing = T)[914] # Create predicted target value as 1 or 0 pred.resp.level <- ifelse(pred.resp$net.result >0.1283,1,0) # Table table(pred.resp.level) ## pred.resp.level ## 0 1 ## 18968 1032 |

Prediction accuracy check using confusion matrix. More details on Model Performance Statistics

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
library(e1071) library(caret) confusionMatrix(data=factor(pred.resp.level), reference=factor(testData$cross.resp), positive='1') ## Confusion Matrix and Statistics ## ## Reference ## Prediction 0 1 ## 0 18106 862 ## 1 980 52 ## ## Accuracy : 0.9079 ## 95% CI : (0.9038079, 0.9118731) ## No Information Rate : 0.9543 ## P-Value [Acc > NIR] : 1.000000000 ## ## Kappa : 0.0052251 ## Mcnemar's Test P-Value : 0.006408847 ## ## Sensitivity : 0.05689278 ## Specificity : 0.94865346 ## Pos Pred Value : 0.05038760 ## Neg Pred Value : 0.95455504 ## Prevalence : 0.04570000 ## Detection Rate : 0.00260000 ## Detection Prevalence : 0.05160000 ## Balanced Accuracy : 0.50277312 ## ## 'Positive' Class : 1 |

Interesting the accuracy level is 90% even with single variable and very simple neural network.

Nice article Ram Sir! Really helpful !

So simple and clear

Could you please share the termCrossSell data set to sasken200k@gmail.com

Thanks Ramesh. I will check and share the dataset

Thank you for such a useful and simple explanation.Is it possible to share the data set used in this example? omnia.raouf@gmail.com

Thank you for soooo useful information. Could you share the data set used in above examples?

Hi Ram

This is a good articale. Could you please share the termCrossSell data set to pravin.kul@gmail.com

-Thanks

Pravin

Thanks Pravin, you could create data from https://archive.ics.uci.edu/ml/datasets/Bank+Marketing

Error in varify.variables(data, formula, startweights, learningrate.limit, :

object 'termCrossSell' not found

You have to first create 'termCrossSell' data frame by reading the data from link provided

good work and explained in a very simple way which is easy to understand