作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我目前正在阅读“使用 Scikit-Learn 和 TensorFlow 进行机器学习实践”。当我尝试重新创建转换管道代码时出现错误。我该如何解决这个问题?
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
num_pipeline = Pipeline([('imputer', Imputer(strategy = "median")),
('attribs_adder', CombinedAttributesAdder()),
('std_scaler', StandardScaler()),
])
housing_num_tr = num_pipeline.fit_transform(housing_num)
from sklearn.pipeline import FeatureUnion
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),
])
# And we can now run the whole pipeline simply:
housing_prepared = full_pipeline.fit_transform(housing)
housing_prepared
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-350-3a4a39e5bc1c> in <module>()
43
44 num_pipeline = Pipeline([
---> 45 ('selector', DataFrameSelector(num_attribs)),
46 ('imputer', Imputer(strategy = "median")),
47 ('attribs_adder', CombinedAttributesAdder()),
NameError: name 'DataFrameSelector' is not defined
最佳答案
DataFrameSelector
未找到,需要导入。它不是 sklearn
的一部分,但在 sklearn-features 中可以找到同名的东西。 :
from sklearn_features.transformers import DataFrameSelector
( DOCS )
关于python - 名称 'DataFrameSelector' 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48491566/
我目前正在阅读“使用 Scikit-Learn 和 TensorFlow 进行机器学习实践”。当我尝试重新创建转换管道代码时出现错误。我该如何解决这个问题? 代码: from sklearn.pipe
我是一名优秀的程序员,十分优秀!