Whenever you try to build a confusion matrix, make sure that both the true values and the prediction values are of “factor” data-type.
Here both pred and testing$Final must be of datatype factor. Here testing$Final is of type int, convert it to factor and then build the confusion matrix.
confusionMatrix(factor(pred, levels=1:490), factor(testing$final, levels=1:490))
We have to keep in mind that both levels should be the same.
table(factor(pred, levels=min(test):max(test)), factor(test, levels=min(test):max(test)))// table is name the confusion matrix
It should give you exactly the same confusion matrix as with the function.
You can also read the Artificial Intelligence Tutorial and join AI Course to get a sparkling start for your AI journey.
If you want to make your career in Artificial Intelligence then go through this video: