Error in ConfusionMatrix the data and reference factors must have the same number of levels Error in ConfusionMatrix the data and reference factors must have the same number of levels r r

Error in ConfusionMatrix the data and reference factors must have the same number of levels


Try use:

confusionMatrix(table(Argument 1, Argument 2)) 

Thats worked for me.


Maybe your model is not predicting a certain factor.Use the table() function instead of confusionMatrix() to see if that is the problem.


Try specifying na.pass for the na.action option:

predictionsTree <- predict(treeFit, testdata,na.action = na.pass)