I have 22 variables (including 1 class variable)
So, i run the following code:
trainIndex <- createDataPartition(dataset$class, p=split, list=FALSE)
data_train <- dataset[ trainIndex,]
data_test <- dataset[-trainIndex,]
model <- NaiveBayes(class~., data=data_train)
data_train$class <- factor(data_train$class)
model <- NaiveBayes(class~., data=data_train)
x_test <- data_test[,1:21]
y_test <- data_test[,22]
it works so far, but whenever i try to did the following command:
predictions <- predict(model, x_test)
it shows the following error:
Error in
[.default
(object$tables[[v]], , nd) : subscript out of bounds In addition: Warning messages:1: In data.matrix(newdata) : NAs introduced by coercion
2: In data.matrix(newdata) : NAs introduced by coercion
3: In data.matrix(newdata) : NAs introduced by coercion
4: In data.matrix(newdata) : NAs introduced by coercion
5: In data.matrix(newdata) : NAs introduced by coercion
6: In data.matrix(newdata) : NAs introduced by coercion
7: In data.matrix(newdata) : NAs introduced by coercion
8: In data.matrix(newdata) : NAs introduced by coercion
9: In data.matrix(newdata) : NAs introduced by coercion
10: In data.matrix(newdata) : NAs introduced by coercion