尽管我不确定为什么会这样,但这似乎很正常。请参阅 sklearn 文档中的示例:https ://scikit-learn.org/stable/modules/impute.html#multivariate-feature-imputation
import numpy as np
from sklearn.experimental import enable_iterative_imputer
from sklearn.impute import IterativeImputer
imp = IterativeImputer(max_iter=10, random_state=0)
imp.fit([[1, 2], [3, 6], [4, 8], [np.nan, 3], [7, np.nan]])
X_test = [[np.nan, 2], [6, np.nan], [np.nan, 6]]
# the model learns that the second feature is double the first
print(np.round(imp.transform(X_test)))
他们np.round
最后使用来获得结果:
array([[ 1., 2.],
[ 6., 12.],
[ 3., 6.]])
在不四舍五入的情况下运行此代码会产生与您类似的结果:
array([[ 1.00007297, 2. ],
[ 6. , 12.00002754],
[ 2.99996145, 6. ]])
尝试np.round
在投射之前添加pd.DataFrame
以查看是否有帮助。