【问题标题】:Customized scikit-learns Transformation and ColumnTransformer error自定义 scikit-learns Transformation 和 ColumnTransformer 错误
【发布时间】:2021-05-08 00:04:24
【问题描述】:

我创建了以下自定义转换,以根据给定的上下分位数对我的数据集进行 Winsorize/剪辑

from sklearn.base import TransformerMixin
import numpy as np
from sklearn.utils.validation import check_is_fitted, check_array

class OutlierExtractor(TransformerMixin):
    def __init__(self, limits=[None, None]):
        self.limits_ = limits

    def fit(self, X, y=None, **fit_params):
        X = check_array(X, copy=self.copy, force_all_finite=False, ensure_2d=False)
        if self.limits_[0] is not None:
            self.a_min_ = np.quantile(X, self.limits_[0], axis=0)
            
        if self.limits_[1] is not None:
            self.a_max_ = np.quantile(X, self.limits_[1], axis=0)
        return self

    def transform(self, X):
        print('transform')
        check_is_fitted(self, ["a_max_", "a_min_"])
        X = check_array(X, copy=self.copy, force_all_finite=False, ensure_2d=False)
        return np.clip(X, self.a_min_, self.a_max_)

当调用ColumnTransformer 时,我收到以下错误消息,表明管道未安装

preprocess_pipeline = ColumnTransformer(
                transformers= [
                    ('ABC', 
                    OutlierExtractor(limits=[0.01, 0.99]) , 
                 ['Feature1', 'Feature2', 'Feature3'])
                         ]
                    , remainder='passthrough'
                )
preprocess_pipeline.fit(df_trn)

错误信息:

NotFittedError:此 OutlierExtractor 实例尚未拟合。称呼 在使用此估算器之前“适合”适当的参数。

我无法确定为什么不使用 ColumnTransformer 函数中提供的 limits 值。

更新:

我想我能够找出问题所在。缺少 get_params 函数。

【问题讨论】:

    标签: python scikit-learn customization pipeline


    【解决方案1】:

    我想我能够找出问题所在。缺少 get_params 函数。

    【讨论】:

      猜你喜欢
      • 2020-04-07
      • 2022-08-12
      • 2020-02-03
      • 2014-09-20
      • 2018-12-20
      • 2021-10-31
      • 2014-04-15
      • 2015-06-09
      • 2016-09-29
      相关资源
      最近更新 更多