Wrong model type for regression error in 10x cross validation for Naive Bayes using R

I implement 10x cross-validation for Naive Bayes from some test data with 2 classes (0 and 1). I followed the steps below and got an error.

data(testdata) attach(testdata) X <- subset(testdata, select=-Class) Y <- Class library(e1071) naive_bayes <- naiveBayes(X,Y) library(caret) library(klaR) nb_cv <- train(X, Y, method = "nb", trControl = trainControl(method = "cv", number = 10)) ## Error: ## Error in train.default(X, Y, method = "nb", trControl = trainControl(number = 10)) : ## wrong model type for regression dput(testdata) structure(list(Feature.1 = 6.534088, Feature.2 = -19.050915, Feature.3 = 7.599378, Feature.4 = 5.093594, Feature.5 = -22.15166, Feature.6 = -7.478444, Feature.7 = -59.534652, Feature.8 = -1.587918, Feature.9 = -5.76889, Feature.10 = 95.810563, Feature.11 = 49.124086, Feature.12 = -21.101489, Feature.13 = -9.187984, Feature.14 = -10.53006, Feature.15 = -3.782506, Feature.16 = -10.805074, Feature.17 = 34.039509, Feature.18 = 5.64245, Feature.19 = 19.389724, Feature.20 = 16.450196, Class = 1L), .Names = c("Feature.1", "Feature.2", "Feature.3", "Feature.4", "Feature.5", "Feature.6", "Feature.7", "Feature.8", "Feature.9", "Feature.10", "Feature.11", "Feature.12", "Feature.13", "Feature.14", "Feature.15", "Feature.16", "Feature.17", "Feature.18", "Feature.19", "Feature.20", "Class"), class = "data.frame", row.names = c(NA, -1L)) 

Also, how to calculate R squared or AUC for this model

Dataset: There are 10,000 records with 20 functions and a binary class.

+6
source share
2 answers

NaiveBayes is a classifier and, therefore, converting Y to factor or logical is the correct way to solve the problem. In your original formulation, a classifier tool was used, but using numeric values ​​and therefore R was confused.

As for the R-square, again this metric is calculated only for regression problems that are not related to classification. There are other indicators to evaluate classification problems, such as Precision and Recall.

For more information about these metrics, see the wikipedia link: http://en.wikipedia.org/wiki/Binary_classification

+8
source

It works after changing the label vector Y <- as.factor (Y)

+3
source

All Articles