Session Ready
Exercise

KNN imputation of categorical values

Once all the categorical columns in the DataFrame have been converted to ordinal values, the DataFrame can be imputed. Imputing using statistical models like K-Nearest Neighbors provides better imputations.

In this exercise, you'll use the KNN() function from fancyimpute to impute the missing values. Lastly, you will also convert the ordinal values back to their respective categories using the ordinal encoder's .inverse_transform() method. Remember, each column's encoder object is present in the ordinal_enc_dict dictionary. The KNN() function and the ordinally encoded DataFrame users has already been imported for you.

Instructions
100 XP
  • Initialize the KNN() imputer.
  • Impute the users DataFrame and round the results.
  • Iterate over columns in users and perform .inverse_tranform() on the ordinally encoded columns.