在学习OReilly.Hands-On.Machine.Learning.with.Scikit-Learn.and.TensorFlow.2017.3时,执行以下代码会出错:
from sklearn.pipeline import FeatureUnion
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
num_attribs = ['longitude',
'latitude',
'housing_median_age',
'total_rooms',
'total_bedrooms',
'population',
'households',
'median_income']
cat_attribs = ["ocean_proximity"]
# 在sklearn 0.19下,由于LabelBinarizer的重写而导致代码失效
num_pipeline = Pipeline([
('selector', DataFrameSelector(num_attribs)),
('imputer', Imputer(strategy="median")

在学习《Hands-On Machine Learning with Scikit-Learn and TensorFlow》时,遇到一个错误:'fit_transform() takes 2 positional arguments but 3 were given'。问题出在sklearn 0.19版本更新了LabelBinarizer,现在只接受两个参数。解决方案是分开处理文本和数值属性,再使用numpy concatenate合并数组。
最低0.47元/天 解锁文章
1万+





