LoslegenKostenlos loslegen

KNN imputation

Datasets always have features which are correlated. Hence, it becomes important to consider them as a factor for imputing missing values. Machine learning models use features in the DataFrame to find correlations and patterns and predict a selected feature.

One of the simplest and most efficient models is the K Nearest Neighbors. It finds 'K' points most similar to the existing data points to impute missing values.

In this exercise, the diabetes DataFrame has already been loaded for you. Use the fancyimpute package to impute the missing values in the diabetes DataFrame.

Diese Übung ist Teil des Kurses

Dealing with Missing Data in Python

Kurs anzeigen

Anleitung zur Übung

  • Import KNN from fancyimpute.
  • Copy diabetes to diabetes_knn_imputed.
  • Create a KNN() object and assign it to knn_imputer.
  • Impute the diabetes_knn_imputed DataFrame.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# Import KNN from fancyimpute
___

# Copy diabetes to diabetes_knn_imputed
diabetes_knn_imputed = ___

# Initialize KNN
knn_imputer = ___

# Impute using fit_tranform on diabetes_knn_imputed
diabetes_knn_imputed.iloc[:, :] = ___
Code bearbeiten und ausführen