From 103beb518fc01535d1a5edb9a8d754816e53ec2c Mon Sep 17 00:00:00 2001 From: Navan Chauhan Date: Tue, 15 Sep 2020 15:53:28 +0530 Subject: Publish deploy 2020-09-15 15:53 --- posts/2019-12-16-TensorFlow-Polynomial-Regression/index.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'posts/2019-12-16-TensorFlow-Polynomial-Regression') diff --git a/posts/2019-12-16-TensorFlow-Polynomial-Regression/index.html b/posts/2019-12-16-TensorFlow-Polynomial-Regression/index.html index b9322b0..75b14ec 100644 --- a/posts/2019-12-16-TensorFlow-Polynomial-Regression/index.html +++ b/posts/2019-12-16-TensorFlow-Polynomial-Regression/index.html @@ -1,9 +1,9 @@ -Polynomial Regression Using TensorFlow | Navan Chauhan
17 minute readCreated on December 16, 2019Last modified on June 1, 2020

Polynomial Regression Using TensorFlow

In this tutorial you will learn about polynomial regression and how you can implement it in Tensorflow.

In this, we will be performing polynomial regression using 5 types of equations -

  • Linear
  • Quadratic
  • Cubic
  • Quartic
  • Quintic

Regression

What is Regression?

Regression is a statistical measurement that is used to try to determine the relationship between a dependent variable (often denoted by Y), and series of varying variables (called independent variables, often denoted by X ).

What is Polynomial Regression

This is a form of Regression Analysis where the relationship between Y and X is denoted as the nth degree/power of X. Polynomial regression even fits a non-linear relationship (e.g when the points don't form a straight line).

Imports

import tensorflow.compat.v1 as tf +Polynomial Regression Using TensorFlow | Navan Chauhan
17 minute readCreated on December 16, 2019Last modified on September 15, 2020

Polynomial Regression Using TensorFlow

In this tutorial you will learn about polynomial regression and how you can implement it in Tensorflow.

In this, we will be performing polynomial regression using 5 types of equations -

  • Linear
  • Quadratic
  • Cubic
  • Quartic
  • Quintic

Regression

What is Regression?

Regression is a statistical measurement that is used to try to determine the relationship between a dependent variable (often denoted by Y), and series of varying variables (called independent variables, often denoted by X ).

What is Polynomial Regression

This is a form of Regression Analysis where the relationship between Y and X is denoted as the nth degree/power of X. Polynomial regression even fits a non-linear relationship (e.g when the points don't form a straight line).

Imports

import tensorflow.compat.v1 as tf tf.disable_v2_behavior() import matplotlib.pyplot as plt import numpy as np import pandas as pd -

Dataset

Creating Random Data

Even though in this tutorial we will use a Position Vs Salary datasset, it is important to know how to create synthetic data

To create 50 values spaced evenly between 0 and 50, we use NumPy's linspace funtion

linspace(lower_limit, upper_limit, no_of_observations)

x = np.linspace(0, 50, 50) +

Dataset

Creating Random Data

Even though in this tutorial we will use a Position Vs Salary dataset, it is important to know how to create synthetic data

To create 50 values spaced evenly between 0 and 50, we use NumPy's linspace function

linspace(lower_limit, upper_limit, no_of_observations)

x = np.linspace(0, 50, 50) y = np.linspace(0, 50, 50)

We use the following function to add noise to the data, so that our values

x += np.random.uniform(-4, 4, 50) y += np.random.uniform(-4, 4, 50) @@ -22,7 +22,7 @@ | Senior Partner | 8 | 300000 | | C-level | 9 | 500000 | | CEO | 10 | 1000000 | -

We convert the salary column as the ordinate (y-cordinate) and level column as the abscissa

abscissa = df["Level"].to_list() # abscissa = [1,2,3,4,5,6,7,8,9,10] +

We convert the salary column as the ordinate (y-coordinate) and level column as the abscissa

abscissa = df["Level"].to_list() # abscissa = [1,2,3,4,5,6,7,8,9,10] ordinate = df["Salary"].to_list() # ordinate = [45000,50000,60000,80000,110000,150000,200000,300000,500000,1000000]
n = len(abscissa) # no of observations plt.scatter(abscissa, ordinate) @@ -32,7 +32,7 @@ plt.show()

Defining Stuff

X = tf.placeholder("float") Y = tf.placeholder("float") -

Defining Variables

We first define all the coefficients and constant as tensorflow variables haveing a random intitial value

a = tf.Variable(np.random.randn(), name = "a") +

Defining Variables

We first define all the coefficients and constant as tensorflow variables having a random initial value

a = tf.Variable(np.random.randn(), name = "a") b = tf.Variable(np.random.randn(), name = "b") c = tf.Variable(np.random.randn(), name = "c") d = tf.Variable(np.random.randn(), name = "d") @@ -304,4 +304,4 @@ plt.title('Quintic Regression Result') plt.legend() plt.show() -

Results and Conclusion

You just learnt Polynomial Regression using TensorFlow!

Notes

Overfitting

> Overfitting refers to a model that models the training data too well.Overfitting happens when a model learns the detail and noise in the training data to the extent that it negatively impacts the performance of the model on new data. This means that the noise or random fluctuations in the training data is picked up and learned as concepts by the model. The problem is that these concepts do not apply to new data and negatively impact the models ability to generalize.

Source: Machine Learning Mastery

Basically if you train your machine learning model on a small dataset for a really large number of epochs, the model will learn all the deformities/noise in the data and will actually think that it is a normal part. Therefore when it will see some new data, it will discard that new data as noise and will impact the accuracy of the model in a negative manner

Tagged with:
\ No newline at end of file +

Results and Conclusion

You just learnt Polynomial Regression using TensorFlow!

Notes

Overfitting

> Overfitting refers to a model that models the training data too well.Overfitting happens when a model learns the detail and noise in the training data to the extent that it negatively impacts the performance of the model on new data. This means that the noise or random fluctuations in the training data is picked up and learned as concepts by the model. The problem is that these concepts do not apply to new data and negatively impact the models ability to generalise.

Source: Machine Learning Mastery

Basically if you train your machine learning model on a small dataset for a really large number of epochs, the model will learn all the deformities/noise in the data and will actually think that it is a normal part. Therefore when it will see some new data, it will discard that new data as noise and will impact the accuracy of the model in a negative manner

Tagged with:
\ No newline at end of file -- cgit v1.2.3