Machine Learning - test set with fewer features than the train set
The train set determines what features you can use for recognition. If you're lucky, your recognizer will just ignore unknown features (I believe NaiveBayes does), otherwise you'll get an error. So save the set of feature names you created during training, and use them during testing/recognition.
Some recognizers will treat a missing binary feature the same as a zero value. I believe this is what the NLTK's NaiveBayesClassifier does, but other engines might have different semantics. So for binary present/absent features, I would write my feature extraction function to always put the same keys in the feature dictionary.
guys.
I was developing an ML model and I got a doubt. Let's assume that my train data has the following data:
ID | Animal | Age | Habitat
0  | Fish   | 2   | Sea
1  | Hawk   | 1   | Mountain
2  | Fish   | 3   | Sea
3  | Snake  | 4   | Forest
If I apply One-hot Encoding, it will generate the following matrix:
ID | Animal_Fish | Animal_Hawk | Animal_Snake | Age | ...
0  | 1           | 0           | 0            | 2   | ...
1  | 0           | 1           | 0            | 1   | ...
2  | 1           | 0           | 0            | 3   | ...
3  | 0           | 0           | 1            | 4   | ...
That's beautiful and work in most of the cases. But, what if my test set contains fewer (or more) features than the train set? What if my test set doesn't contain "Fish"? It will generate one less category.
Can you guys help me how can I manage this kind of problem?
Thank you