# polynomial regression Scikit learn tutorial

Table of Contents

1. What is poly regression
2. Linear regression vs Polynomial regression
3. Example
4. Video Tutorial

1 what is polynomial regression

1. polynomial regression generally used when the data is not into a linear distribution.
2. Most of the time data may not be necessary in a linear distribution now if we fit a linear regression on that data model will not fit well and does not gives us the accurate value
3. That’s why Polynomial regression comes into place to fit on polynomial distributed value

2 linear regression vs polynomial regression

linear regression only works for the simple hyperplane line

y =mX +C

we can see in this picture the value of the raw data which has been distributed. Figure-1 Figure-2

linear vs polynomial regression

let’s consider the mean square error of linear regression and polynomial regression predicted curve that is being given for example. Linear regression tends to have high mean square error. More the mean square error the less it’s accurate so it should be

3 Example of polynomial regression in sklearn

Let’s dive deep into the example and see how it works so we are calling the necessary libraries followed by reading the salary Figure-3
1. Data that we have is salary data is the data in which we are given the positions the level of experience followed by the salary which has been provided so we have a level of 1 to 10 followed by from business analysts to the CEO
2. The challenge here is to predict the salary for the level of 8.5 which is not provided in the data frame.

comparing the linear model against the polynomial regression model

1. we are calling the linear regression function from sklearn.linear_model and fitting the value of x and y.
2. we can see the linear regression has recorded and trained the value for x and y
3. Now let’s call for the polynomial regression from pre-processing and into polynomial feature now once that is done
4. we have to define the degree for which we are considering the value so here we are considering degree equals to 4 as for the given value provided
5. once that is done what we do is that we fit the value of the X and transform it so it’s called as fit and transform at the same time the x value is now changed according to the X polynomial regression that we have called for the degree of X once that is done
6. we will fit the value inside the fit function of the X polynomial and the Y value that we were having followed by calling the regression class and now since the degree of X is being changed we can fit in the linear regression.

Let visualize regression line in both cases Figure-5
1. so as we can see all the values in present inside the data is being crossed by the polynomial regression and as we can see this is filed for the best results that we have caught from the data which was distributed
2. let’s see how much values just both of them has predicted so here are the two values for the predictive value of 8.5 level of experience

linear regression has predicted it is 41 and the polynomial recognition predicted as 38 Figure-6
1. So we observed our data we consider it as 38 which would be much much closer to 8.5 polynomial regression value is much more accurate and closer to the original one.
2. Much important thing here is changing your model according to the data distribution.