我想用sklearn np.nan
的平均值填充SimpleImputer
值,但是引发了valueError
。
from sklearn.impute import SimpleImputer
imputer = SimpleImputer(strategy='mean')
imputer.fit(house_numeric)
答案 0 :(得分:0)
我尝试了您的代码并出现错误:
ValueError: Expected 2D array, got 1D array instead:
array=[ 1. 2. 3. 4. nan 7. 8. 9.].
Reshape your data either using array.reshape(-1, 1) if your data has a single
feature or array.reshape(1, -1) if it contains a single sample.
如果您的错误相同,请尝试重塑您的house_numeric,以便:
house_numeric = house_numeric.reshape(-1,1)
答案 1 :(得分:0)
我认为上面的答案非常好。首先,重塑数据,然后重新设计。
from sklearn.preprocessing import Imputer
# Setup the Imputation transformer: imp
imp = Imputer(missing_values='NaN', strategy='mean', axis=0)