Should replacing missing values for categorical variables be done after one-hot-encoding? (ex: I have a column named Car Type: Sedan, Hatchback, MPV, SUV) which has 5% missing values. Would there be any implications if I were to go with either of one of these methods replacing missing values first -> one hot encoding andone hot encoding -> replace missing value?

  • $\begingroup$ Are you sure you want to/can reliably replace the missing value? Or should there be an indicator for missing value only? $\endgroup$
    – Craig
    Commented Aug 5, 2022 at 15:24
  • $\begingroup$ I would like to replace the missing values with suitable values instead of indicating that it is missing $\endgroup$ Commented Aug 6, 2022 at 5:18
  • $\begingroup$ Then assuming you have some reliable way to infer the missing value is accurate and you did the research to understand what/why missings are occurring, replace it before encoding. The code should be easier since it is only looking in 1 column and replacing there. You might also want to examine the model with and without imputing these values. Imputing missing values can easily add bias, especially with no indicator variable. Perhaps you are using an algorithm that supports missing values and you may want to keep it missing. $\endgroup$
    – Craig
    Commented Aug 8, 2022 at 12:55


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.