编码实现
多项式特征

-  第1列代表项
-  第2列代表项
-  第3列代表项
-  第4列代表项
-  第5列代表项
-  第6列代表项
Pipeline
作用:简化PolynomialFeatures语法
因为只需要掌握Pipeline语法即可,因此只给出这块代码。
x = np.random.uniform(-3, 3, size=100)
X = x.reshape(-1, 1)
y = 0.5 * x**2 + x + 2 + np.random.normal(0, 1, 100)
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
# 初始化配置
poly_reg = Pipeline([
("poly", PolynomialFeatures(degree=2)),
("std_scaler", StandardScaler()),
("lin_reg", LinearRegression())
])
# 建模
poly_reg.fit(X, y)
y_predict = poly_reg.predict(X)
# 可视化
plt.scatter(x, y)
plt.plot(np.sort(x), y_predict[np.argsort(x)], color='r')
plt.show()



 
 
                         
                                

