0
votes

This is the line with the error:

predicted <-predict(fit, test_data)

This is the code for testing the model for predicting the income

The error that I got was:

Error in model.frame.default(Terms, newdata, na.action = na.action, xlev = object$xlevels) : factor education has new levels 10th, 11th, 12th, 1st-4th, 5th-6th, 7th-8th, 9th, Assoc-acdm, Assoc-voc, Bachelors, Doctorate, HS-grad, Masters, Preschool, Prof-school, Some-college

1
looks like you trained your model with a certain set of levels for education, and that the new data has new levels it didn't see by training : provide training data with all possible levels if you want the model to make predictions.Waldi
To this point, it may be helpful if you share str(df) for your training model and the test_data.Todd Burus
don't worry, I got the solution and answered below.Fatty Acids

1 Answers

0
votes

Got it!

Just needed to factorize the education column

train_data$education = factor(train_data$education)