Help me for campus work :(

Hi everyone nice to see u all. i have problem with my r and this is my first in r i want to tell u about my NB
kelompok 1 navie bayes kedala2|690x368

#INPUT DATA
peduliaku=read.delim("clipboard")
View(peduliaku)
#MEMANGGIL PACKAGES
library(e1071)
library(caret)
#MEMBAGI DATA MENJADI 2 BAGIAN
sampel=sample(1:nrow(peduliaku),0.6*nrow(peduliaku),replace=TRUE)
training=data.frame(peduliaku)[sampel,]
testing=data.frame(peduliaku)[-sampel,]
#MEMBUAT MODEL NAVIEBAYES
modelNB=naiveBayes(VALUE~.,data=training)
#MELAKUKUAN PREDIKSI
prediksi=predict(modelNB,testing)
hasil=confusionMatrix(table(prediksi,testing$VALUE))
hasil

if i run the program in NB appear the message!
Error in table(prediksi, testing$VALUE) :
all arguments must have the same length
can you all helpme to fix the error.?
thankss help me :frowning: for campus work

VALUE must be a factor, is it ?

library(e1071)
library(caret)
(peduliaku <- data.frame(
  x=1:100,
  VALUE= factor(c(rep(0,60),rep(1,40))),
  VALUEbad= c(rep(0,60),rep(1,40))
))
#MEMBAGI DATA MENJADI 2 BAGIAN
sampel=sample(1:nrow(peduliaku),0.6*nrow(peduliaku),replace=TRUE)
training=data.frame(peduliaku)[sampel,]
testing=data.frame(peduliaku)[-sampel,]


#bad ?

#MEMBUAT MODEL NAVIEBAYES
modelNB=naiveBayes(VALUEbad~x,data=training)
#MELAKUKUAN PREDIKSI
prediksi=predict(modelNB,testing)
hasil=confusionMatrix(table(prediksi,testing$VALUEbad))
hasil


# good ! 
#MEMBUAT MODEL NAVIEBAYES
modelNB=naiveBayes(VALUE~x,data=training)
#MELAKUKUAN PREDIKSI
prediksi=predict(modelNB,testing)
hasil=confusionMatrix(table(prediksi,testing$VALUE))
hasil

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.