I am trying to make predictions using a random forest model in R.
However I get errors since some factors have different values in the test set than in the training set. For example, a factor Cat_2
has values 34, 68, 76
, etc., in the test set that do not appear in the training set. Unfortunately, I do not have control over the Test set... I must use it as-is.
My only workaround was to convert the problematic factors back to numerical values, using as.numeric()
. It works but I am not very satisfied, since these values are codes that have no numerical sense...
Do you think there would be another solution, to drop the new values from the test set? But without removing all the other factor values (let say values 1, 2, 14, 32
, etc.) which are in both training and test, and contains information potentially useful for predictions.