# Working of Neural Network

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.

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 Modulesimport pandas as pd# import the data setdata_set = pd.read_csv(‘vaibhav.csv’)# Independent VariableX=data_set.iloc[:,2:6]# Dependent variableY=data_set.iloc[:,6]# Split the values of X and Y in train testfrom sklearn.model_selection import train_test_splitX_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 moduleimport kerasfrom keras.layers import Densefrom keras.models import Sequential# Initialising the Neural Network Moduleclassifier = Sequential()# 1 hidden layerclassifier.add(Dense(units = 3, kernel_initializer = ‘he_uniform’,activation=’relu’,input_dim = 4))# 2 hidden layerclassifier.add(Dense(units = 3, kernel_initializer = ‘he_uniform’,activation=’relu’))# Output layerclassifier.add(Dense(units = 1, kernel_initializer = ‘glorot_uniform’, activation = ‘sigmoid’))# Complie the Modelclassifier.compile(optimizer = ‘Adamax’, loss = ‘binary_crossentropy’, metrics = [‘accuracy’])# Fit the Modelfit_model =classifier.fit(X_train, Y_train,validation_split=0.33, batch_size = 8, epochs = 50)`

Enjoy Happy Coding…..

I am passionate software developer working in different technologies like Python, ML, Django and JavaScript.

## More from Vaibhav Mishra

I am passionate software developer working in different technologies like Python, ML, Django and JavaScript.