TypeError:fit()缺少1个必需的位置参数:“ X”

时间:2019-02-07 14:03:34

标签: python-3.x

我尝试的代码是-

X = dataset.iloc[:,:].values
from sklearn.preprocessing import Imputer
imputer = Imputer(missing_values = 'Nan', strategy = 'mean', axis = 0)
imputer = Imputer.fit(X[:,2:52])
X[:,2:52] = imputer.transform(X[:,2:52])

我遇到的错误是- TypeError:fit()缺少1个必需的位置参数:“ X”

1 个答案:

答案 0 :(得分:2)

imputer = Imputer(...)创建Imputer的新实例。当您要使用此实例时,只需像imputer.method(args)那样调用它即可。因此正确的用法应该是这样的:

X = dataset.iloc[:,:].values
from sklearn.preprocessing import Imputer
imputer = Imputer(missing_values = 'Nan', strategy = 'mean', axis = 0)
imputer.fit(X[:,2:52])
X[:,2:52] = imputer.transform(X[:,2:52])