如何修复“ TypeError:fit()缺少1个必需的位置参数:'X'”的错误

时间:2019-01-29 04:06:50

标签: python scikit-learn

我正在尝试使用LinearRegression

拟合模型
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import PolynomialFeatures
from sklearn.pipeline import make_pipeline
X_train, X_test, y_train, y_test = train_test_split(x, y)
mod = make_pipeline(PolynomialFeatures(degree=1), 
LinearRegression(normalize=True))
mod.fit(x=X_train, y=y_train)

并收到错误消息

fit() missing 1 required positional argument: 'X'

请问如何解决?

1 个答案:

答案 0 :(得分:1)

对于Pipeline.fit

Docs说大写X,请尝试:

mod.fit(X=X_train, y=y_train)