尝试运行此
from sklearn.impute import SimpleImputer
imputer = SimpleImputer(missing_values ="NaN", strategy = "mean")
imputer = SimpleImputer.fit(X[:,1:3])
X[:,1:3] = SimpleImputer.transform(X[:,1:3])
我遇到错误
TypeError:fit()缺少1个必需的位置参数:“ X”
但是我已经提供了x,对不对? 解决方案是什么?
答案 0 :(得分:2)
答案 1 :(得分:1)
完全工作的代码如下:
from sklearn.impute import SimpleImputer
imputer = SimpleImputer(missing_values = np.nan, strategy = "mean")
imputer = imputer.fit(X[:,1:3])
X[:,1:3] = imputer.transform(X[:,1:3])
请注意:
missing_values = np.nan
答案 2 :(得分:0)
您的代码:
def add_to_db(d):
report = Report(**d)
db.session.add(report)
db.session.commit()
正确的代码:
from sklearn.impute import SimpleImputer
# PAY ATTENTION: to NaN as np.nan
imputer = SimpleImputer(**missing_values ="NaN"**, strategy = "mean")
imputer = SimpleImputer.fit(X[:,1:3])
# PAY ATTENTION: instead of "SimpleImputer.transform" use "imputer.transform"
X[:,1:3] = **SimpleImputer**.transform(X[:,1:3])