Working of Neural Network

Original Source Here

What is Neural Network?

Neural Network is set of algorithm which follows the working of human brain.
It has dense cells called neurons which are helpful for system to learn things. For neural network we need at least 3 layers, Input layer, hidden layer and output layer. Hidden layer can be multiple on the basis of requirement or it’s accuracy.

Working of Forward Neural Network

Input Layer:

In the above diagram there is 3 features x1, x2, and x3 which will help our model to train.

For each feature there is weight associated with them w1, w2 and w3. A good neural network always have distinct weights. So question comes up Why we need weight? Answer: Weights decide how much input values will affect our output. It means that weight decide how fast activation function will work.

For Deep understanding lets take a real life example, Suppose we pull 2 kg weight with left hand and 5 kg weight with right hand. In this process there are multiple neurons will work to tell the brain which is heavier. Right hand will activate early as compare to left hand and tell the brains this is heavier.

Hidden Layer :

Hidden layer makes the network faster and pass only important info to next layer. It will process what all the things are coming from previous layer. Suppose we need to identify Bus, So if only wheels can’t identify the bus , we need conjunctions of another parts to identify a bus. Hidden layers do all these processing. Hidden layer input can be calculated by below example.

y = activation(x1*w1+x2*w2+x3*w3+ bias)

Output Layer :

Output layer will produce the final result. Output layer is only one in a neural network. The output layer takes the input from its previous hidden layer and performs the calculations. Output layer input can be calculated by below example.

z = activation(y*w4)

Example Code :

# Importing the Modules
import pandas as pd
# import the data set
data_set = pd.read_csv(‘vaibhav.csv’)
# Independent Variable
X=data_set.iloc[:,2:6]
# Dependent variable
Y=data_set.iloc[:,6]
# Split the values of X and Y in train test
from sklearn.model_selection import train_test_split
X_train, X_test, Y_train, Y_test = train_test_split(X,Y, test_size=0.3, random_state=0)
from sklearn.preprocessing import StandardScaler
# Standardize the features
std_sca = StandardScaler()
X_train = std_sca.fit_transform(X_train)
X_test = std_sca.transform(X_test)
# Importing Keras module
import keras
from keras.layers import Dense
from keras.models import Sequential
# Initialising the Neural Network Module
classifier = Sequential()
# 1 hidden layer
classifier.add(Dense(units = 3, kernel_initializer = ‘he_uniform’,activation=’relu’,input_dim = 4))
# 2 hidden layer
classifier.add(Dense(units = 3, kernel_initializer = ‘he_uniform’,activation=’relu’))
# Output layer
classifier.add(Dense(units = 1, kernel_initializer = ‘glorot_uniform’, activation = ‘sigmoid’))
# Complie the Model
classifier.compile(optimizer = ‘Adamax’, loss = ‘binary_crossentropy’, metrics = [‘accuracy’])
# Fit the Model
fit_model =classifier.fit(X_train, Y_train,validation_split=0.33, batch_size = 8, epochs = 50)

Enjoy Happy Coding…..

AI/ML

Trending AI/ML Article Identified & Digested via Granola by Ramsey Elbasheer; a Machine-Driven RSS Bot



via WordPress https://ramseyelbasheer.wordpress.com/2021/03/01/working-of-neural-network/

Popular posts from this blog

I’m Sorry! Evernote Has A New ‘Home’ Now

Jensen Huang: Racism is one flywheel we must stop

How to Install C++ Programs From Source Code Using Make in WSL2