修改后的代码:
from sklearn.preprocessing import PolynomialFeatures, StandardScaler from sklearn.pipeline import Pipeline from sklearn.linear_model import Ridge
def fit_and_predict(X_train, y_train, X_test):
# X_train: numpy二维数组,由n个样本、k个特征组成的数据矩阵,形状是(n,k)。
# y_train: numpy一维数组,由n个数据组成的标签,形状是(n,)。
# X_test: numpy二维数组,由m个测试、k个特征组成的数据矩阵,形状是(m,k)。
model = Pipeline([
('poly', PolynomialFeatures(6)),
('scaler', StandardScaler()),
('ridge', Ridge(alpha=0.3))
])
model.fit(X_train, y_train)
return model.predict(X_test)