Error in model.frame.default file for Predict () - "Factor has new levels" - for Char Variable

I have a dataset that I split into a test / train dataset. Immediately after this split, I created a logistic model with:

logModel1 = glm(Y ~ . -var1 -var2 -var3, data=train, family=binomial)

If I use this model for predictions on one set, I get no error (although, of course, not a super-useful test of my model). So I used the code below to predict on my test suite:

predictLog1 <- predict(logModel1, type="response", newdata=test)

But I get the following error:

Error in model.frame.default (terms, newdata, na.action = na.action, xlev = object $ xlevels): factor myCharVar has new levels. this is myCharVar observation, This is different ...

Here's what got me particularly confused:

  • myCharVar - , . str(test$myCharVar) str(train$myCharVar)
  • myCharVar .

2 SO: " " ,

, , , , . , "-myCharVar". - , - " ", .

+4
1

, , , , myCharVar . z~.-y, z~(x+y)-y.

, : predict(): " , , newdata . , , , ".

, , myCharVar. myCharVar , . myCharVar, ( , glm . , ). , , , .

this , .

+5

Source: https://habr.com/ru/post/1584688/


All Articles