第二章 PipeLine的示例代码运行出错
vine3401 opened this issue · 0 comments
vine3401 commented
关于特征缩放的代码,就是下面这个Pipeline转换流水线
num_attribs = list(housing_num)
cat_attribs = ["ocean_proximity"]
num_pipeline = Pipeline([
('selector', DataFrameSelector(num_attribs)),
("imputer", Imputer(strategy="median")),
("attribs_adder", CombinedAttributesAdder()),
("std_scaler", StandardScaler()),
])
cat_pipeline = Pipeline([
('selector', DataFrameSelector(cat_attribs)),
('label_binarizer', LabelBinarizer()),
])
full_pipeline = FeatureUnion(transformer_list=[
("num_pipeline", num_pipeline),
("cat_pipeline", cat_pipeline)
])
housing_prepared = full_pipeline.fit_transform(housing)
运行报错如下:TypeError: fit_transform() takes 2 positional arguments but 3 were given
,
查了网上资料后发现是版本问题,LabelBinareizer
的fit_transform
函数参数定义改变了:
"""
The pipeline is assuming LabelBinarizer's fit_transform method is defined to take three positional arguments:
"""
def fit_transform(self, x, y)
...rest of the code
while it is defined to take only two:
def fit_transform(self, x):
...rest of the code
希望能解决一哈,虽然找到了问题,但不知道咋改(新手QAQ)