Polynomial Regression Algorithm used in ML section

What is Polynomial Regression?
That algorithm is internally used by Bolt Cloud and Y’all are just making us apply it.
I need to know how to implement that algorithm. Instead of just applying it.

Polynomial Regression is a form of linear regression in which the relationship between the independent variable x and dependent variable y is modeled as an nth degree polynomial. Polynomial regression fits a nonlinear relationship between the value of x and the corresponding conditional mean of y, denoted E(y |x)

A polynomial regression is an application of multiple linear regression - the distinction is only the names. For example, whether you write
newdemo
wherez=x^2 you have the same model. The ‘linear’ in ‘linear regression’ means the function you estimate is linear in the coefficients.

Why Polynomial Regression:

  • There are some relationships that a researcher will hypothesize is curvilinear. Such types of cases will include a polynomial term.
  • Inspection of residuals. If we try to fit a linear model to curved data, a scatter plot of residuals (Y-axis) on the predictor (X-axis) will have patches of many positive residuals in the middle. Hence in such a situation, it is not appropriate.
  • An assumption in usual multiple linear regression analysis is that all the independent variables are independent. In the polynomial regression model, this assumption is not satisfied.

In short…
We use polynomial regression to transform a linear model to better fit our nonlinear data.
You may be wondering why its called polynomial regression. The method is named so because we transform our linear equation into a polynomial equation
Mmm… below are the two images
Now you decide which looks better…

Fig. (1)
dash1
Fig. (2)
dash2

Here we can see that the data is the second Fig. (2) is accurately displayed!!

There are times when a curved line works better than a straight line.
So Using polynomial regression over here greatly increases accuracy…

The basic goal of regression analysis is to model the expected value of a dependent variable y in terms of the value of an independent variable x. In simple regression, we used following equation –

y= a + bx + e

Here y is dependent variable, a is y intercept, b is the slope and e is the error rate.

In many cases, this linear model will not work out For example if we analyzing the production of chemical synthesis in terms of temperature at which the synthesis take place in such cases we use quadratic model

y= a + b1x + b2^2 + e

Here y is dependent variable on x, a is y intercept and e is the error rate.

In general, we can model it for nth value.

y = a + b1x + b2x^2 +…+ bnx^n

Since regression function is linear in terms of unknown variables, hence these models are linear from the point of estimation.

Hence through Least Square technique, let’s compute the response value that is y.

The Algorithm goes like this:

Step 1: Import libraries and dataset
Import the important libraries and the dataset we are using to perform Polynomial Regression.

Step 2: Dividing the dataset into 2 components.
Divide dataset into two components that is X and y.X will contain the Column between 1 and 2. y will contain the 2 column.

Step 3: Fitting Linear Regression to the dataset.
Fitting the linear Regression model On two components.

Step 4: Fitting Polynomial Regression to the dataset.
Fitting the Polynomial Regression model on two components X and y.

Step 5: In this step we are Visualising the Linear Regression results using scatter plot.

Step 6: Visualising the Polynomial Regression results using scatter plot.

Step 7. Predicting new result with both Linear and Polynomial Regression.

Advantages of using Polynomial Regression

  • Broad range of function can be fit under it.
  • Polynomial basically fits wide range of curvature.
  • Polynomial provides the best approximation of the relationship between dependent and independent variable.

Disadvantages of using Polynomial Regression

  • These are too sensitive to the outliers.
  • The presence of one or two outliers in the data can seriously affect the results of a nonlinear analysis.
  • In addition there are unfortunately fewer model validation tools for the detection of outliers in nonlinear regression than there are for linear regression.

Assume that we have the data of the room temperature taken at the interval of every 10 seconds and we want to predict the future values of the temperature using these data point values. This can be done by fitting a curve or an equation by finding the pattern in the data using Machine learning algorithms.

Sometimes, the trend of data is not really linear, and looks curvy. In this case we can use Polynomial regression methods. In fact, many different regressions exist that can be used to fit whatever the dataset looks like, such as quadratic, cubic, and so on, and it can go on and on to infinite degrees.

In essence, we can call all of these, polynomial regression, where the relationship between the independent variable x(Time) and the dependent variable y(Temperature) is modeled as an nth degree polynomial in x. Lets say you want to have a polynomial regression (let’s make 2 degree polynomial):

y=b+theta1(x)+theta2(x2)