How to solve "The data cannot have more levels than the reference" error when using confusioMatrix?
<p>I'm using R programming.
I divided the data as train &amp; test for predicting accuracy.</p>

<p>This is my code:</p>

<pre><code>library("tree")
credit&lt;-read.csv("C:/Users/Administrator/Desktop/german_credit (2).csv")

library("caret")
set.seed(1000)

intrain&lt;-createDataPartition(y=credit$Creditability,p=0.7,list=FALSE)
train&lt;-credit[intrain, ]
test&lt;-credit[-intrain, ]

treemod&lt;-tree(Creditability~. , data=train)
plot(treemod)
text(treemod)

cv.trees&lt;-cv.tree(treemod,FUN=prune.tree)
plot(cv.trees)

prune.trees&lt;-prune.tree(treemod,best=3)
plot(prune.trees)
text(prune.trees,pretty=0)

install.packages("e1071")
library("e1071")
treepred&lt;-predict(prune.trees, newdata=test)

confusionMatrix(treepred, test$Creditability)
</code></pre>

<p>The following error message happens in <code>confusionMatrix</code>:</p>

<blockquote>
  <p>Error in confusionMatrix.default(rpartpred, test$Creditability) : the data cannot have more levels than the reference</p>
</blockquote>

<p>The credit data can download at this site.<br>
<a href="http://freakonometrics.free.fr/german_credit.csv" rel="nofollow">http://freakonometrics.free.fr/german_credit.csv</a></p>