0

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

duckmayr
  • 16,303
  • 3
  • 35
  • 53
  • What is this function "createDataPartition()" ? Also, would be good if you provide an example! – Cainã Max Couto-Silva Oct 03 '18 at 22:58
  • i am trying to do split by using the command >split=0.80 –  Oct 03 '18 at 23:02
  • 1
    @CainãMaxCouto-Silva it's from the caret package. Ahmad, it's good practice to show the packages that you are using for a minimum reproducible example. Could you provide us with a sample of your data. Also, you should factor your data if it's numeric BEFORE you create a partition using `createPartition`. We don't know what the variable `split` is either. Please see https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Brandon Bertelsen Oct 04 '18 at 00:11

0 Answers0