Sklearn Pipeline - 如何在自定义 Transformer(不是 Estimator)中继承 get_params
Sklearn Pipeline - How to inherit get_params in custom Transformer (not Estimator)
我在 scikit-learn 中有一个管道,它使用我定义如下的自定义转换器:
class MyPipelineTransformer(TransformerMixin):
定义函数
__init__, fit() and transform()
但是,当我在 RandomizedSearchCV 中使用管道时,出现以下错误:
'MyPipelineTransformer' object has no attribute 'get_params'
我已在线阅读(例如下面的链接)
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)
我在 scikit-learn 中有一个管道,它使用我定义如下的自定义转换器:
class MyPipelineTransformer(TransformerMixin):
定义函数
__init__, fit() and transform()
但是,当我在 RandomizedSearchCV 中使用管道时,出现以下错误:
'MyPipelineTransformer' object has no attribute 'get_params'
我已在线阅读(例如下面的链接)
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)