error in confusion matrix the data cannot have more levels than the reference
<p>I've trained an SVM model. I'm now trying to generate a confusion matrix and keep getting the following error:</p>

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

<p>Here is the code </p>

<pre><code>model &lt;- svm(FAVOURITES_COUNT~., data = data_train);

test.pred &lt;- predict(model, data_test,na.action = na.pass);

confusionMatrix(test.pred,data_test$FAVOURITES_COUNT)
</code></pre>

<p>I have tested if they have same levels using:</p>

<pre><code>&gt; identical (levels(test.pred), levels(data_test$FAVOURITES_COUNT))
[1] TRUE
</code></pre>

<p>structure of both <code>pred</code> and <code>data_test$FAVOURITES_COUNT</code>:</p>

<pre><code>&gt;  str(test.pred)  Named num [1:440] 1539 1516 1560 1560 1450 ...
&gt;  - attr(*, "names")= chr [1:440] "1" "4" "11" "13" ...

&gt; str(data_test$FAVOURITES_COUNT)
 int [1:440] 62 10725 84 84 19 99 54 84 84 84 ...
</code></pre>

<p>I think the problem is related to chr and int different types but I don't know how to solve this , there is already another question like this but it doesn't provide a solution also if I change the chr to int</p>

<pre><code>pred&lt;-as.integer(format(round(predict(model,data_test))))
</code></pre>

<p>the problem is still there. How can I resolve this error</p>

<p>Dataset </p>

<p><a href="https://sheet.zoho.com/sheet/editor.do?doc=e32b61b756876ffa8e5926811820cfdef2c92d14405606ef3fbcf1fdeaae0b619727171e8d6a42530234dde72d427b2297382d024282dadbe3197ac15b68f139" rel="nofollow noreferrer">data</a></p>

<p>complete code</p>

<pre><code>rm(list=ls())
df &lt;- read.csv("path/data.csv")
mydata &lt;- df
mydata$ALTMETRIC_ID &lt;- NULL


#library(caret)
split=0.60
trainIndex &lt;- createDataPartition(mydata$FAVOURITES_COUNT, p=split, list=FALSE)
data_train &lt;- mydata[ trainIndex,]
data_test &lt;- mydata[-trainIndex,]
#library(e1071)

model &lt;- svm(FAVOURITES_COUNT~., data = data_train);

test.pred &lt;- predict(model, data_test,na.action = na.pass);

confusionMatrix(test.pred,data_test$FAVOURITES_COUNT)
</code></pre>