Machine Learning - test set with fewer features than the train set

Viewed 5956

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

2 Answers
Related