我尝试的代码是-
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”
答案 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])