What is Polynomial Regression?
Polynomial Regression is a form of a linear regression which forms a relationship between the dependent variable ‘y’ and independent variable ’x’ with nth degree polynomial. Polynomial regression is a linear model.
In order to understand the Polynomial Regression, we first analyze the problem solved in Simple Linear Regression.
So, in the above image simple linear regression scatter points helps to build the model.
But, if points are scattered in this way :
Then, if we fit our simple linear regression model in this plot. It would be difficult and do not give accurate predictions.
But, the curve line best fits the scatter points.
Now, Let's build the model with the help of Polynomial Regression. We are using a dataset having salaries at each level.
We need to follow some basic steps:
Step 1: Import the Libraries
Step 2. Importing the Dataset
Step 3. Split the data into a matrix of features(X) and the dependent variable(y).
Step 4: Fitting a Polynomial model to test and training the dataset. We can select the ‘degree’ as per the best fit line. For now, we just do the analysis with degree=2.
Step 5:Now we do the visualization part and do the analysis with degree=2.
You can see the fitting is not proper, in order to do a best-fit line change the degree or increase the value of a degree and again do the analysis. Now doing analysis with degree=3.
Repeat the process until we find the best-fit line. Now taking degree=4.
Again, repeat the process until we find the best-fit line. Now taking degree=5.
Now, you can see the threshold is achieved where our line is best fitted.