我在 scikit-learn 中有一个管道,它使用我定义的自定义转换器,如下所示:
class MyPipelineTransformer(TransformerMixin):
定义函数
__init__, fit() and transform()
但是,当我在 RandomizedSearchCV 中使用管道时,出现以下错误:
'MyPipelineTransformer' object has no attribute 'get_params'
我已经在线阅读(例如下面的链接)
(Python - sklearn) How to pass parameters to the customize ModelTransformer class by gridsearchcv
http://scikit-learn.org/stable/auto_examples/hetero_feature_union.html
我可以通过从 BaseEstimator 继承来获取“get_params”,而不是我当前的代码仅从 TransformerMixin 继承。但是我的变压器不是估算器。从 BaseEstimator 继承非估计器有什么缺点吗?或者这是为管道中的任何转换器(估计器或非估计器)获取 get_params 的推荐方法?
最佳答案
是的,看起来这是实现此目标的标准方法。例如in the source for sklearn.preprocessing
我们有
class FunctionTransformer(BaseEstimator, TransformerMixin)
关于python - Sklearn Pipeline - 如何在自定义 Transformer(不是 Estimator)中继承 get_params,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39092383/