I got an error when I'm doing naive Bayes by R, here's my code and error
library(e1071)
#data
train_data <- read.csv('https://raw.githubusercontent.com/JonnyyJ/data/master/train.csv',header=T)
test_data <- read.csv('https://raw.githubusercontent.com/JonnyyJ/data/master/test.csv',header=T)
efit <- naiveBayes(y~job+marital+education+default+contact+month+day_of_week+
poutcome+age+pdays+previous+cons.price.idx+cons.conf.idx+euribor3m
,train_data)
pre <- predict(efit, test_data)
bayes_table <- table(pre, test_data[,ncol(test_data)])
accuracy_test_bayes <- sum(diag(bayes_table))/sum(bayes_table)
list('predict matrix'=bayes_table, 'accuracy'=accuracy_test_bayes)
ERROR:
bayes_table <- table(pre, test_data[,ncol(test_data)]) Error in table(pre, test_data[, ncol(test_data)]) : all arguments must have the same length accuracy_test_bayes <- sum(diag(bayes_table))/sum(bayes_table) Error in diag(bayes_table) : object 'bayes_table' not found list('predict matrix'=bayes_table, 'accuracy'=accuracy_test_bayes) Error: object 'bayes_table' not found
I really don't understand what's going on, because I'm new in R
length(pre)
,length(test_data[,ncol(test_data)])
– YOLO