Error analysis of multiple linear regression in R language model.frame.default

Error in model.frame.default(Terms, Newdata, Na. action = Na. action, Xlev = Object $Xlevels) : A new level appears in factor factor(O)
Make sure the test and train data sets have the same factor level when you set them. In short, each factor level should be stored in test and train at the same time. Otherwise, how can you look up the data, rewrite the code, it is useless.

It would seem test and train datasets have a different set of factor levels.

Read More: