Simple Neural network for beginners using Tensorflow
Tensorflow:
Tensorflow is a powerful python package for easy development and deployment on various applications. State of the art researcher uses Tensorflow for their research works. Tensorflow provides a beautiful ecosystem for the developers of different streams. such as, Machine learning developers, Web developers, App developers. This Package has been used in many languages such as, Python development, JavaScript development, Swift development and IOS development, IOT development.
How to get started with Tensorflow?
Installation
Currently Tensorflow supports, 64-bit OS, Win 7 or later, Ubuntu 16.04 or later, Mac 10.12.6 or later (with no GPU support). The Python version that support Tensorflow are, Python version 3.5 to 3.7
Install using pip python package manager in python,
To get current stable installation — pip install tensorflow
To get unstable latest version of tensorflow — pip install tf-nightly
Simple Neural network algorithm:
So, the equation is so simple, y = x*5. We will train the tensorflow model with the help of Keras Sequential Model.
1) Importing packages from Tensorflow, Pandas and Numpy. (Note: Ignoring Future warnings are optional).
2) Defining the Model with single layer and single neuron or perceptron, which is the Dense layer and the parameter units says how many perceptron are in that Dense layer. Input shape defines the dimension of input data.
3) Compile the model with optimizer as SGD — Stochastic Gradient Descent, and Loss function as Mean squared error.
4) Now our model is ready, let’s give the training data to the model. In this example, I have used data from a CSV file.
5) Fit the model with epochs of 500, after training the model can able to predict the Y value for new X value.
Data contains two values X and Y.
The code for the program,
Result
we know that the result would be 50, but after the training our model can able to predict nearer to the 50(49.81). Thus we created our neural network for a simple equation.
Advantages of Tensorflow package:
- Easy development and deployment.
- Support integration for many languages.
- Better performance for graph computation.
- Easy debugging and support scalability.
Thanks for reading the post, Hope you like it.