Impute missing data using k-Nearest Neighbors (KNN)

Question

Suppose you're given a matrix, M, containing categorical features:

 [[1, 1.2, 1.9],
  [0, 1.7, 1.3],
  [1, 1.5, 1.2],
  [0, -.2, -1.2]]

Additionally, you're given a matrix, M_null, with some missing values:

 [[np.nan, 1.5, 1.2],
  [np.nan, -.3, -.7]]

Given these matrices, fill the missing values using k-Nearest Neighbors (KNN) imputation.

Solution

Access restricted

Subscribe to premium account to see the solution.

Get premium now