I have trained model using random forest algorithm. Now I want to predict results using this model on data set which contains only one records.
When I tried to execute predict command it throw following error.
Error in predict.randomForest(model, test1, type = "response") : Type of predictors in new data do not match that of the training data.
Noticed that it is because of different levels for factor variable in training and testing data frame.
So I found one solution in stakoverflow to modify levels using script
common <- intersect(names(train), names(test1))
for (p in common) { if (class(train[[p]]) == "factor") { levels(test1[[p]]) <- levels(train[[p]]) } }
Please refer to below link query.
r random forest error - type of predictors in new data do not match
But, unfortunately it changes the value in data for most of the variables.
For example:
In test1 data frame there is one variable name "Category" having value ">=100" it changes to "11-50"