is k nearest neighbors classification code example

Example 1: 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. ]])

Example 2: k nearest neighbor

The k-nearest neighbors (KNN) algorithm is a simple,supervised machine learning
algorithm that can be used to solve both classification and regression problems.

Tags:

Misc Example