`[.default`(object $ tables [[v]],,nd)错误:下标超出范围

时间:2018-10-03 22:50:31

标签: r rstudio naivebayes

我有22个变量(包括1个类变量)

因此,我运行以下代码:

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]

到目前为止,它仍然有效,但是每当我尝试执行以下命令时:

predictions <- predict(model, x_test)

它显示以下错误:

  

[.default(object $ tables [[v]],,nd)中的错误:下标超出范围   另外:警告消息:

     

1:在data.matrix(newdata)中:强制引入的NAs

     

2:在data.matrix(newdata)中:强制引入的NAs

     

3:在data.matrix(newdata)中:强制引入的NAs

     

4:在data.matrix(newdata)中:强制引入的NAs

     

5:在data.matrix(newdata)中:强制引入的NAs

     

6:在data.matrix(newdata)中:强制引入的NAs

     

7:在data.matrix(newdata)中:强制引入的NAs

     

8:在data.matrix(newdata)中:强制引入的NAs

     

9:在data.matrix(newdata)中:强制引入的NAs

     

10:在data.matrix(newdata)中:强制引入的NAs

0 个答案:

没有答案