ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
Perceptrion using tensorflow
1. Venkat Java Projects
Mobile:+91 9966499110 Visit:www.venkatjavaprojects.com
Email:venkatjavaprojects@gmail.com
Introduction
As you know a perceptron serves as a basic building block for creating a deep neural
network therefore, it is quite obvious that we should begin our journey of mastering
Deep Learning with perceptron and learn how to implement it using TensorFlow to
solve different problems. In case you are completely new to deep learning, I would
suggest you to go through the previous blog of this Deep Learning Tutorial series to
avoid any confusion. Following are the topics that will be covered in this blog on
Perceptron Learning Algorithm:
Perceptron as a Linear Classifier
Implementation of a Perceptron using TensorFlow Library
SONAR Data Classification Using a Single Layer Perceptron
Types of Classification Problems
One can categorize all kinds of classification problems that can be solved using neural
networks into two broad categories:
Linearly Separable Problems
Non-Linearly Separable Problems
Basically, a problem is said to be linearly separable if you can classify the data set into
two categories or classes using a single line. For example, separating cats from a group
of cats and dogs. On the contrary, in case of a non-linearly separable problems, the
data set contains multiple classes and requires non-linear line for separating them into
their respective classes. For example, classification of handwritten digits. Let us
visualize the difference between the two by plotting the graph of a linearly separable
problem and non-linearly problem data set:
2. Venkat Java Projects
Mobile:+91 9966499110 Visit:www.venkatjavaprojects.com
Email:venkatjavaprojects@gmail.com
Since, you all
are familiar with AND Gates, I will be using it as an example to explain how a
perceptron works as a linear classifier.
Note: As you move onto much more complex problems such as Image Recognition,
which I covered briefly in the previous blog, the relationship in the data that you want to
capture becomes highly non-linear and therefore, requires a network which consists of
multiple artificial neurons, called as artificial neural network.
Perceptron as AND Gate
As you know that AND gate produces an output as 1 if both the inputs are 1 and 0 in all
other cases. Therefore, a perceptron can be used as a separator or a decision line that
divides the input set of AND Gate, into two classes:
Class 1: Inputs having output as 0 that lies below the decision line.
Class 2: Inputs having output as 1 that lies above the decision line or separator.
3. Venkat Java Projects
Mobile:+91 9966499110 Visit:www.venkatjavaprojects.com
Email:venkatjavaprojects@gmail.com
The below diagram shows the above idea of classifying the inputs of AND Gate using a
perceptron:
Till now, you understood that a linear perceptron can be used to classify the input data
set into two classes. But, how does it actually classify the data?
Mathematically, one can represent a perceptron as a function of weights, inputs and
bias (vertical offset):
Each of the input received by the perceptron has been weighted based on the
amount of its contribution for obtaining the final output.
Bias allows us to shift the decision line so that it can best separate the inputs into
two classes.
Activation Functions
As discussed earlier, the activation function is applied to the output of a perceptron as
shown in the image below:
4. Venkat Java Projects
Mobile:+91 9966499110 Visit:www.venkatjavaprojects.com
Email:venkatjavaprojects@gmail.com
In the previous example, I have shown you how to use a linear perceptron with relu
activation function for performing linear classification on the input set of AND Gate. But,
what if the classification that you wish to perform is non-linear in nature. In that case,
you will be using one of the non-linear activation functions. Some of the prominent non-
linear activation functions have been shown below:
TensorFlow library provides built-in functions for applying activation functions. The built-
in functions w.r.t. above stated activation functions are listed below:
tf.sigmoid(x, name=None)
o Computes sigmoid of x element-wise
o For an element x, sigmoid is calculated as – y = 1 / (1 + exp(-x))
tf.nn.relu(features, name=None)
o Computes rectified linear as – max(features, 0)
tf.tanh(x, name=None)
o Computes hyperbolic tangent of x element wise
So far, you have learned how a perceptron works and how you can program it using
TensorFlow. So, it’s time to move ahead and apply our understanding of a perceptron to
solve an interesting use case on SONAR Data Classification.
SONAR Data Classification Using Single Layer
Perceptrons
In this use case, I have been provided with a SONAR data set which contains the data
about 208 patterns obtained by bouncing sonar signals off a metal cylinder (naval mine)
and a rock at various angles and under various conditions. Now, as you know, a naval
mine is a self-contained explosive device placed in water to damage or destroy surface
ships or submarines. So, our goal is to build a model that can predict whether the object
is a naval mine or rock based on our data set.
5. Venkat Java Projects
Mobile:+91 9966499110 Visit:www.venkatjavaprojects.com
Email:venkatjavaprojects@gmail.com
Here, the overall fundamental procedure will be same as that of AND gate with few
difference which will be discussed to avoid any confusion. Let me provide you a walk-
through of all the steps to perform linear classification on SONAR data set using Single
Layer Perceptron:
Now that you have a good idea about all the steps involved in this use case, let us go
ahead and program the model using TensorFlow:
Execution:
Double clickonrun.batand belowUIapplicationwill open.
6. Venkat Java Projects
Mobile:+91 9966499110 Visit:www.venkatjavaprojects.com
Email:venkatjavaprojects@gmail.com
Nowclickon Upload“Upload SonatDataset”.
Load the Sonar Datasetfrom the local drive.
8. Venkat Java Projects
Mobile:+91 9966499110 Visit:www.venkatjavaprojects.com
Email:venkatjavaprojects@gmail.com
Data Preprocessingisdone.Nowclickon“”Generate trainandtestdata for model”.
Train andTest data issplite fromthe givendataset.Now clickon“SLPTrain” will trainthe model using
tensorflow.
9. Venkat Java Projects
Mobile:+91 9966499110 Visit:www.venkatjavaprojects.com
Email:venkatjavaprojects@gmail.com
Trainingdone fortrain data andNowwe have to predictthe testdata and calculate the accuracy.
We got an accuracy of 80%.