I have data of format, for example, ['1', '5' '6', '5', '2'], where each label can be a character of any number between 0-9. The nature of my data is nominal categorical, so it is unordered, and subsequently, I use the scikit OneHotEncoder to categorically encode my data. However, I run into an error when testing the model when, let's say I have ['1', '5', '9', '3', '1'] when there was no input where the third index of the array was '9'.
I think this is being caused because when I encode the data, and let's say in the test data the third index only has numbers from '0'-'8', the OneHotEncoder doesn't recognize when a '9' is in the third index, and throws an error. I'm wondering if there is a way to manually add these categories, so in the ML model the category would be there and just have no data points on it.
Example:
from sklearn.preprocessing import OneHotEncoder
a = [['1'], ['2'], ['3'], ['5']]
enc = OneHotEncoder()
X = enc.fit_transform(a)
enc.transform([['4']])
You can see that my training data does not contain '4', even though '4' is a possible label. so when I encode it and transform '4', it throws an error:
ValueError: Found unknown categories ['4'] in column 0 during transform
I'm wondering how I could manually add '4' as a category.