Suppose I have a data set which consists a dependent variable y
and independent variables X
. Suppose that there is a specific variable x
which is a categorical variable; suppose that it takes values good
and best
in the training data. I would be inclined to use an ordinal encoder, such as OrdinalEncoder
from sklearn.preprocessing
. This would map good --> 1
and best --> 0
, say.
Suppose that the model I'm using requires no NA
s. My hypothetical dataset is lovely and has no NA
s! Grand. I train it.
I now come to the test set. In this, the variable x
sees a new value: bad
. I would, obviously, have wanted to set this to 2
. What should I do? Should I look at the entire dataset when encoding? This seems dodgy. Plus, if I add more data in the future, I might run into the same issue: maybe I see really bad
.
Might this simply be classed as "bad practice". I should make sure that I know all the options in advance so that I can encode them appropriately in the first place.
If I were doing one-hot encoding, such as with OneHotEncoder
, I'd be fine. I'd just write a 0
in the column representing "is x
good
/bad
?" and be done. But something more intelligent needs to be done with the ordinal version. Is it ok to just stick in a value of 2
retrospectively? Seems dodgy...
X
" - ifX
were independent variables then any modelling would be useless. You probably meant to say thatX
are regressors, predictors, explanatory variables or any other synonymous term. Let's phase out misnomers. $\endgroup$y
is the dependent variable andX
form the independent ones. I know people in data science like to use stats terms and then just give them new names, so maybe this is one of those. I'm not sure. My ds is knowledge is limited! $\endgroup$