Knn imputation using scikit-learn

3.5k views Asked by At

I am trying to impute missing values in my dataset by using Knn. Could anyone suggest me a concept of this method and how to do this by using Knn in scikit-learn.

Thank you in advance.

1

There are 1 answers

0
A R MOHAMMED On

you can use KNN imputer from Sklearn, Note: works only on numerical data not on categorical, I know because I tried on categorical

import numpy as np

from sklearn.impute import KNNImputer

X = [[1, 2, np.nan], [3, 4, 3], [np.nan, 6, 5], [8, 8, 7]]

imputer = KNNImputer(n_neighbors=2)

imputer.fit_transform(X)

please go to this link for more info