📅  最后修改于: 2022-03-11 14:46:54.483000             🧑  作者: Mango
# Nearest neighbors imputation
import numpy as np
from sklearn.impute import KNNImputer
nan = np.nan
X = [[1, 2, nan], [3, 4, 3], [nan, 6, 5], [8, 8, 7]]
imputer = KNNImputer(n_neighbors=2, weights="uniform")
imputer.fit_transform(X)
# array([[1. , 2. , 4. ],
# [3. , 4. , 3. ],
# [5.5, 6. , 5. ],
# [8. , 8. , 7. ]])