1

Before fitting the training data in the linear model I have added the new level of factor column present in test data to my training data factor column. Still logistic regression model throwing following error while predicting with test dataset:

Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) : factor Parch has new levels 9

> classifier1 <- glm(formula=Survived ~ . , family = binomial,data = train_final[-1])
> predicted.values1 <- predict(classifier1, newdata = test_final[-1], type='response')# for logistic regression
Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) : 
  factor Parch has new levels 9
> levels(train_final$Parch)
[1] "0" "1" "2" "3" "4" "5" "6" "9"
> levels(test_final$Parch)
[1] "0" "1" "2" "3" "4" "5" "6" "9"
> unique(train_final$Parch)
[1] 0 1 2 5 3 4 6
Levels: 0 1 2 3 4 5 6 9
> unique(test_final$Parch)
[1] 0 1 3 2 4 6 5 9
Levels: 0 1 2 3 4 5 6 9
>
NelsonGon
  • 13,015
  • 7
  • 27
  • 57
Soumen Das
  • 31
  • 1
  • 7
  • If that doesn't solve your issue, please make your question [reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – NelsonGon Oct 20 '19 at 08:24

0 Answers0