What is polynomial regression?
A simple linear regression algorithm only works when the relationship between the data is linear.
However, if we have non-linear data, linear regression will not be able to draw a best-fit line.
Simple regression analysis fails in such conditions.
There is a dataset with a non-linear relationship, as shown in the image below. You can see that the linear regression results do not perform well, meaning they do not come close to reality.

To overcome this problem, we introduce polynomial regression, which helps identify the curvilinear relationship between independent and dependent variables.
Polynomial regression is a form of linear regression where, due to the non-linear relationship between dependent and independent variables, we add some polynomial terms to linear regression to convert it into polynomial regression.
As a result, the formula for multiple linear regression is expressed as the formula below.
Example
Code
1
2
3
4
5
from sklearn.preprocessing import PolynomialFeatures
poly_reg = PolynomialFeatures(degree=4) #x^0, x^1, ~ x^n dgree
X_poly = poly_reg.fit_transform(X)
lin_reg_2 = LinearRegression()
lin_reg_2.fit(X_poly, y)
Result
