Polynomial Regression in Python using Sci-kit
Concept of machine learning
Introduction
Before jumping into Polynomial regression, let us first understand what is regression and why do we use it? A regression is nothing but a statistical way of determining the character and strength of a relationship between a single dependent variable. This method is mainly seen in the finance and investment sectors. A simple example can be y = x.
Now, coming to Polynomial regression is a type of regression that determines the relationship based on the nth degree of a polynomial. The higher the degree, the more curved will be your regression.
Eg: x^2, x^3
Oftentimes, it is not necessary that whatever data we get is perfect. We face issues when the relationship between a feature and a response variable cannot be depicted in a straight line like the image shown below:
You can see that there are so many outliers, and this may affect the actual representation and provide us with the wrong information. So, let us now see how we can fix this and make it into a proper polynomial regression model.
Note: Make sure you install python libraries like NumPy, matplotlib, and pandas before starting to code.
Let us consider a similar example of the above diagram. Below is the program of how the chart is created:
Program 1
import numpy as np
import pandas as np
import matplotlib.pyplot as pltx = np.arange(0, 30)y = [3, 4, 5, 7, 10, 8, 9, 10, 10, 23, 27, 44, 50, 63, 67, 60, 62, 70, 75, 88, 81, 87, 95, 100, 108, 135, 151, 160, 169, 179]plt.figure(figsize=(10,6))
plt.scatter(x,y)
plt.show()
Output: