-1

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

Martin Gal
  • 16,640
  • 5
  • 21
  • 39
  • Is `newcredit` consistent to `credit_ctree` namely does it have the same structure, same named colums? – Martin Gal Jun 13 '21 at 22:26
  • 1
    Also it's a good start to give some data, usally using `dput(head(YourData)` and make a [great reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Martin Gal Jun 13 '21 at 22:27

1 Answers1

0

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.

AndrewGB
  • 16,126
  • 5
  • 18
  • 49