how to debug “factor has new levels” error for linear model and prediction
问题 I am trying to make and test a linear model as follows: lm_model <- lm(Purchase ~., data = train) lm_prediction <- predict(lm_model, test) This results in the following error, stating that the Product_Category_1 column has values that exist in the test data frame but not the train data frame): factor Product_Category_1 has new levels 7, 9, 14, 16, 17, 18 However, if I check these they definitely look to appear in both data frames: > nrow(subset(train, Product_Category_1 == "7")) [1] 2923 >