Polynomial regression using scikit-learn
Now we will fit the polynomial regression model to the dataset. #fitting the polynomial regression model to the dataset from sklearn.preprocessing import PolynomialFeatures poly_reg=PolynomialFeatures(degree=4) X_poly=poly_reg.fit_transform(X) poly_reg.fit(X_poly,y) lin_reg2=LinearRegression() lin_reg2.fit(X_poly,y)
python - Polynomial Regression using sklearn - Stack Overflow
stackoverflow.com › questions › 51706459Mar 28, 2021 · import numpy as np from sklearn.preprocessing import PolynomialFeatures from sklearn.linear_model import LinearRegression from sklearn.pipeline import make_pipeline X=np.array([[1, 2, 4]]).T print(X) y=np.array([1, 4, 16]) print(y) model = make_pipeline(PolynomialFeatures(degree=2), LinearRegression(fit_intercept = False)) model.fit(X,y) X_predict = np.array([[3]]) print(model.named_steps.linearregression.coef_) print(model.predict(X_predict))