R Prediction After Creating the Model

146 Views Asked by At

I get the following error after running

p <- predict(credit_ctree,newdata=newcredit)

I can't see the way to get it to come out right.

Error in checkData(oldData, RET) : Classes of new data do not match original data

1

There are 1 best solutions below

0
On

Your newdata newcredit likely does not have the same levels as your credit_ctree on the factor variables. One thing you can do is to check the levels on each oof your variables (not sure what your model looks like). You could check levels like this: levels(newcredit$var) and levels(credit_ctree$var), where var is the variable that you used in the model. The levels must be equal or you will get an error.

But it's difficult to be more specific or to solve the problem without any reproducible data (including your model). Please see: How to make a great r reproducible example.