Answers for "Nearest neighbors imputation"

0

Nearest neighbors imputation

# 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. ]])
Posted by: Guest on April-22-2020

Python Answers by Framework

Browse Popular Code Answers by Language