Polynomial Regression is a form of regression where the relationship between the dependent variable y and the independent variable x is modeled as an nth degree polynomial.
Formula for Polynomial Regression
Code snippet
from sklearn.preprocessing import PolynomialFeatures
poly_regr = PolynomialFeatures(degree = 2)
X_poly = poly_regr.fit_transform(X)
poly_regr.fit(X_poly, y)
reg = LinearRegression()
reg.fit(X_poly, y)
degree is the degree of the polynomial features.
Refer plots below with varying degree and observe that as degree value increases, the curve becomes more aligned to the data
Degree 2
Degree 3
Degree 5
Formula for Polynomial Regression
Code snippet
from sklearn.preprocessing import PolynomialFeatures
poly_regr = PolynomialFeatures(degree = 2)
X_poly = poly_regr.fit_transform(X)
poly_regr.fit(X_poly, y)
reg = LinearRegression()
reg.fit(X_poly, y)
degree is the degree of the polynomial features.
Refer plots below with varying degree and observe that as degree value increases, the curve becomes more aligned to the data
Degree 2
Degree 3
Degree 4
Degree 5
No comments:
Post a Comment