Simple Neural network for beginners using Tensorflow

Balayogi G
Analytics Vidhya
Published in
2 min readFeb 10, 2020

--

source : Tensorflow.org

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

This is how the equation will look if we plot it

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.

Data set for this neural network

The code for the program,

Program for simple Neural network

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.

If we plot the result.

Advantages of Tensorflow package:

  1. Easy development and deployment.
  2. Support integration for many languages.
  3. Better performance for graph computation.
  4. Easy debugging and support scalability.

Thanks for reading the post, Hope you like it.

--

--

Balayogi G
Analytics Vidhya

PhD Student at Pondicherry University, Research in HCI, Web Accessibility, NLP, Computer Vision