The Best Fluffy Pancakes recipe you will fall in love with. Full of tips and tricks to help you make the best pancakes.
If you are aspiring to learn about Neural networks, then you are at right place. Here I’m going to give a detail note on Artificial Neural network with a common examples.
What is Neural Network ?
Neural Network is series of algorithms that are trying to resemble as human brain and finding the relation between human brain and Data sets. It is used in various cases like regression, classification, Image Recognition and many more.
Unlike there are differences between biological neural network and Artificial Neural Network. The major difference is biological neural network does process the message parallelly whereas Artificial Neural Network process serially also slowly in the former one and faster in latter one.
Artificial Neural Networks
Artificial Neural Network(ANN) is like a brain as basis to develop algorithms that can be used to model complex patterns and prediction problems. It work as a similar function brain.
If we look in to the functioning of brain it is a major part in body that contains a billion number of cells called neurons. These neurons passes the information in the form of electric signals. Any information from external or stimuli is received by the dendrites of the neuron, process the information in neuron cell body, and converts it into output and passed through the Axon to the next neuron. The next neuron can choose to accept or reject the information given by the neuron based on signal strength.
An Artificial Neural Network is a computational network based on biological neural networks that construct the structure of the human brain has neurons that are linked to each other in various layers the networks.
Architecture of ANN
A Neural Network has many layers and each layer has specific function and as the layers increases the complexity increases
The Neural Network has Three types of layers:
1. Input Layer – It accepts inputs in several formats given by the programmer
2. Hidden Layer – It is the layer between input and output. It do all calculations to find hidden features and patterns.
3. Output Layer – The input goes through a series of transformations using the hidden layer, which finally results in output that is conveyed using this layer.
The artificial neural network takes input and computes the weighted sum of the inputs and includes a bias. This computation is represented in the form of a transfer function.
Advantages of ANN
Parallel Processing capacity:
ANN can perform more than one task simultaneously.
Storing Data on entire Network:
It stores data ion whole network, not only in data base. Because losing of data at one part cannot prevents the network from working.
Capability to work with Incomplete knowledge:
After training ANN, It may produces output even with inadequate data. The effectiveness of output is based on the data we loss.
Having fault tolerance:
Removing one or more cells from ANN does not prohibit it from generating output, and this makes fault-tolerance in network
Disadvantages of ANN
The ANN execute parallel processing ,so they need process that supports parallel processing. So it is hardware dependent.
Cannot determine Network Structure:
As it is similar to working of brain functions, we cannot determine the network structure of Neural Networks.
Difficultness in understanding problem statement:
As not only ANN, but static modules are also get trained with numeric data, it becomes difficult for the ANN to understand the problem statement.
Time Duration of Network is unknown:
Due to reduction of network to a specific value of error, this doesn’t give optimum results.
How Does ANN Work ?
As we know ANN contains three layers of network for processing, the diagrammatic representation of layers is as follows:
In the above picture, each neuron have some weights and biases.
Here combination = bias + weights * input (F = w1*x1+w2*x2+w3*x3) and finally activation function is applied output = Activation (combination)
Here in the picture Activation is Output. There are many other activation functions are there like ReLU, Leaky ReLU, tanh, and so on..
Here at first inputs are given to the input layer which transfers it to the hidden layer. The interconnection between these two layers assign weights to each input at initial points randomly and bias is added. After that the Combination weights and bias is passed to the Activation Function. Activation Function calculates the output by firing the necessary node for feature extraction of output. This process is known as Foreward Propagation. After getting output it is compared with original output and the error is known. Then weights are updated in backward propagation to reduce error. Finally Prediction is done.
Practical Example of ANN
For understanding working of ANN in a practical we need a colab for code practicing
We can get our colab from google by following link
By going to file option you can make your own new notebook.
Here we see about the Telco Churn Dataset
Now first we import library pandas from Keras library.
# Import Library
import pandas as pd
Now Import files to the Google colab
#Import the files to Google Colab
url = 'https://raw.githubusercontent.com/rc-dbe/bigdatacertification/master/dataset/churn_trasnsformed_new.csv'
df_csv = pd.read_csv(url, sep=',',)
Now define how many rows should be to show up
# Show 10 first Row
Now remove unnamed romans with specification
# Remove "Unnamed:O" Coloumn
df = df_csv.drop("Unnamed: 0", axis=1)
Now check the data information
# Check the Data Infomation
Now import the Min max scalar and initialize it. Then transform all attributes
#Import MinMax Scaler
from sklearn.preprocessing import MinMaxScaler
# initialize min-max scaler
mm_scaler = MinMaxScaler()
column_names = df.columns.tolist()
# Transform all attributes
df[column_names] = mm_scaler.fit_transform(df[column_names])
Now remove the future which is not being used and set the target.
# Selecting the Feature, by remove the unused feature
feature = ['Churn']
train_feature = df.drop(feature, axis=1)
# Set The Target
train_target = df["Churn"]
Now check the future
# Show the Feature
Now split the Data and check the training Data
# Split Data
from sklearn.model_selection import train_test_split, cross_val_score
X_train, X_test, y_train, y_test = train_test_split(train_feature ,train_target, shuffle = True, test_size=0.3, random_state=1)
# Show the training data
For training the ANN model we use MLPClassifier from Scikit Learn Library. So lets import the library and define fitting model and give prediction to Test Dataset.
# Import Library
from sklearn.neural_network import MLPClassifier
# Fitting Model
mlp = MLPClassifier(hidden_layer_sizes=(5), activation = 'relu', solver = 'adam',max_iter= 10000, verbose = True)
mlp = mlp.fit(X_train,y_train)
# Prediction to Test Dataset
y_predmlp = mlp.predict(X_test)
Now print number of layers, Iterations and current loss with computed function
print('Number of Layer =', mlp.n_layers_)
print('Number of Iteration =', mlp.n_iter_)
print('Current loss computed with the loss function =', mlp.loss_)
Now we evaluate the model using Confussion Matrix
Import the Metric class and Initialize Confussion Matrix
# Import the metrics class
from sklearn import metrics
# Confussion Matrix
cnf_matrixmlp = metrics.confusion_matrix(y_test, y_predmlp)
Now get the Accuracy, Precision, Recall, F1 score, and Cohens kappa score and print the values
# Show the Accuracy, Precision, Recall, F1, etc.
acc_mlp = metrics.accuracy_score(y_test, y_predmlp)
prec_mlp = metrics.precision_score(y_test, y_predmlp)
rec_mlp = metrics.recall_score(y_test, y_predmlp)
f1_mlp = metrics.f1_score(y_test, y_predmlp)
kappa_mlp = metrics.cohen_kappa_score(y_test, y_predmlp)
print("F1 Score:", f1_mlp)
print("Cohens Kappa Score:", kappa_mlp)
By this way we implement and Train the Artificial Neural Networks
Applications of ANN
There are many applications on ANN. Some of them are:
- Image Processing and Character Recognition
- Credit Rating
- Fraud Detection
- Portfolio management
For more about different types of neural networks see this link
For more working examples of Artificial Neural Network see this links
The video tutorial for working model of ANN see this link