nearest neighbors imputation

Solutions on MaxInterview for nearest neighbors imputation by the best coders in the world

showing results for - "nearest neighbors imputation"
Abigail
29 Apr 2019
1# Nearest neighbors imputation
2
3import numpy as np
4from sklearn.impute import KNNImputer
5nan = np.nan
6X = [[1, 2, nan], [3, 4, 3], [nan, 6, 5], [8, 8, 7]]
7imputer = KNNImputer(n_neighbors=2, weights="uniform")
8imputer.fit_transform(X)
9# array([[1. , 2. , 4. ],
10#        [3. , 4. , 3. ],
11#        [5.5, 6. , 5. ],
12#        [8. , 8. , 7. ]])