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
>