Table of Contents
- What is poly regression
- Linear regression vs Polynomial regression
- Video Tutorial
1 what is polynomial regression
- polynomial regression generally used when the data is not into a linear distribution.
- 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
- 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.
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
- 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
- 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
- we are calling the linear regression function from sklearn.linear_model and fitting the value of x and y.
- we can see the linear regression has recorded and trained the value for x and y
- Now let’s call for the polynomial regression from pre-processing and into polynomial feature now once that is done
- 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
- 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
- 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
- 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
- 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
- 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.
- Much important thing here is changing your model according to the data distribution.