我如何解决使用 feature_engine 时出现的 TypeError

How can i solve the TypeError gotten while working with feature_engine

我正在使用 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)

但是在调用转换方法时它 returns 一个 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'

通过查看您提供的堆栈跟踪,在我看来这似乎是 feature_engine 与旧版本 scikit-learn 之间的不兼容。在旧版本中(例如 0.21), attributes was a mandatory parameter for check_is_fitted, but in newer versions (e.g. 0.23)它是可选的:

If None, estimator is considered fitted if there exist an attribute that ends with a underscore and does not start with double underscore.