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



我正在使用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:UsersHPDesktopHashkaggleHousing 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)
~Anaconda3libsite-packagesfeature_enginemissing_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 
~Anaconda3libsite-packagesfeature_enginebase_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(中,attributescheck_is_fitted的强制参数,但在新版本(例如0.23(中它是可选的:

如果None,如果存在以下划线结尾而不以双下划线开头的属性,则认为estimator已拟合。

最新更新