python - Sklearn Pipeline - 如何在自定义 Transformer(不是 Estimator)中继承 get_params

标签 python inheritance scikit-learn pipeline

我在 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/

相关文章:

python - 解释来自 RandomForestClassifier 的特征重要性值

machine-learning - sklearn SVM默认距离测量

python - 如何针对 sci-kit 学习库中的某一类别对 SVM 进行惩罚?

python - 在 Plotly 中为同一实体绘制 2 个不同的数据源

python - 这是作为元组值的 python switch 语句执行函数的 "pythonic"方法吗?

python - 操作长串位的数据结构

C++对象交互

java - Android 类层次结构和与 Fragment 的接口(interface)

python - 使用 Python Paramiko 的嵌套 SSH

node.js - 将 sequelize 模型实例传递给服务在 express.js 中不起作用