使用Feature_engine时如何解决TypeError

时间:2020-08-05 00:43:23

标签: python pandas machine-learning scikit-learn feature-engineering

我正在使用feature_engine来填充缺失的值

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# from feature-engine
from feature_engine import missing_data_imputers as mdi

#Working with House Data and Feature Engine__Practice
cols_to_use = [
    'BsmtQual', 'FireplaceQu', 'LotFrontage', 'MasVnrArea', 'GarageYrBlt',
]
data = pd.read_csv(r'C:\Users\HP\Desktop\Hash\kaggle\Housing Project/train.csv', usecols=cols_to_use)

我创建了一个mdi实例以适合我的数据

imputer = mdi.MeanMedianImputer(imputation_method='median')
imputer.fit(data)

但是在调用transform方法时,它返回一个TypeError,我找不到它发生的原因。

tmp = imputer.transform(data)

这是返回的错误

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-39-2f486acb96bd> in <module>
----> 1 tmp = imputer.transform(data)

~\Anaconda3\lib\site-packages\feature_engine\missing_data_imputers.py in transform(self, X)
    103     # Ugly work around to import the docstring for Sphinx, otherwise none of this is necessary
    104     def transform(self, X):
--> 105         X = super().transform(X)
    106         return X
    107 

~\Anaconda3\lib\site-packages\feature_engine\base_transformers.py in transform(self, X)
     35 
     36         # Check method fit has been called
---> 37         check_is_fitted(self)
     38 
     39         # check that input is a dataframe

TypeError: check_is_fitted() missing 1 required positional argument: 'attributes'

1 个答案:

答案 0 :(得分:1)

通过查看您提供的堆栈跟踪,在我看来,这就像feature_engine与scikit-learn的旧版本之间的不兼容。在较旧的版本(例如0.21)中,attributescheck_is_fitted的必需参数,但在较新的版本(例如0.23)中它是可选的:

如果None,则estimator被认为是适合的,如果存在以下划线结尾但不以双下划线开头的属性。