R Naive Bayes Confusion Matrix

Creating a classifier i get an error - all arguments must have the same length.
Wonder how to fix it?

classifier <- naiveBayes (x=trainset, y= train$Label)
prediction <- predict(classifier, newdata=testset)
cm <- table(test$Label, prediction)
Error in table(test$Label, prediction) : 
  all arguments must have the same length

UPD: Found it, the target variable should be factor

The variable prediction is made using testset but in trying to make cm you use test$Label. Should that be testset$Label?

Can you please provide a minimal reprex (reproducible example)? The goal of a reprex is to make it as easy as possible for me to recreate your problem so that I can fix it: please help me help you!

If you've never heard of a reprex before, start by reading "What is a reprex", and follow the advice further down that page.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.