Simple TensorFlow Model To Predict a Linear Regression

Introduction

In this article, we will learn to create a simple TensorFlow model to predict value based on the linear regression equation.

Steps To Build the Model

Let us first generate the data needed for the model, although I am using less data so it won’t be much accurate. Below is a screenshot of the snippet to generate data; in order to view the complete code, visit my git repo here.

Linear progression prediction screenshot

Now we have generated some data based on the equation y=mx+c.

Next, let us create a simple model where we provide units and input_shape as 1 because we are only providing one number in the input and expecting one number as the output.

Following is the snippet for creating a model:

snippet for creating the model

Now let us predict something new: we have the equation y=mx+c where we will have x= 40, and we know while generating data, we passed m=2, and c=1, so as per the equation, the value should be y =2*40+1=81

Following is the snippet for the predicted value:

Snippet for the predicted value

Conclusion

We have learned the very basic model for predicting Linear regression values.

This UrIoTNews article is syndicated fromDzone