1问题的来源:“Scikit-Learn&TensorFlow动手机器学习”第二章加州房价预测案例
提示:未定义名称“DataFrameSelector”
2,解决办法
- 安装第三方sklearn-features库,pip install sklearn-features(注:DataFrameSelector为第三方库的方法;文档地址https://sklearn-features.readthedocs.io/en/stable/index.html )
- 完成后,
- 运行时会有新的问题提示:fit_transform()需要2个位置参数,但是给出了3个
- 通过降低scikit学习版本,0.18可以运行;或者在0.19版本的基础上将LabelBinarizer()更换成
CategoricalEncoder(encoding="onehot-dense")
- 在更换方法后,会遇到新的错误提示:名称'CategoricalEncoder'未定义(注:0.19版本并未提供该方法,属于未来版的scikit-learn v0.20.dev0)
- 需要在代码前创建CategoricalEncoder类
from sklearn.base import BaseEstimator, TransformerMixin from sklearn.utils import check_array from sklearn.preprocessing import LabelEncoder from scipy import sparse class CategoricalEncoder(BaseEstimator, TransformerMixin): """Encode categorical features as a numeric array. The input to this transformer should be a matrix of integers or strings, denoting the values taken on by categorical (discrete) features. The features can be encoded using a one-hot aka one-of-K scheme (``encoding='onehot'``,