Additional factor level in test data which causes no prediction


#1

Hi,

How to handle a categorical variable having 3 levels in training data but with 4 levels in test data while predicting?
This is giving error while predicting…

Please advise.

Regards


#2

Hi @manalykum.

If you are using R, simply add the 4th level to the training set manually using:

levels(trainSet)<-c(‘1’,‘2’,‘3’,‘4’)