tapply中的错误(var,y,mean,na.rm = TRUE):参数必须具有相同的长度

时间:2017-03-31 23:41:39

标签: r

为什么我会收到此错误?什么是tapply意思?我甚至都没用过这种方法?

发生错误:naive_model< -naiveBayes(X_train,Y_train)

错误:

from("direct://some/uri/name")

代码:

Error in tapply(var, y, mean, na.rm = TRUE) : 
  arguments must have same length

dataset

整个代码

  library(e1071)
  #Naive Bayes
  #Learn Time
  start.time <- Sys.time()
  naive_model <-naiveBayes(X_train,Y_train)
  end.time <- Sys.time()
  time.taken <- end.time - start.time
  naivebayes_Learnruntime[i]<- time.taken

  #Prediction Time
  start.time <- Sys.time()
  pred = predict(naive_model,X_test)
  end.time <- Sys.time()
  time.taken <- end.time - start.time
  naivebayes_Predictruntime [i]<- time.taken

1 个答案:

答案 0 :(得分:2)

错误表示+-----------+-------------+---------+ | SubjectID | AttributeID | ValueID | +-----------+-------------+---------+ | 1 | 1 | 1 | | 1 | 2 | 1 | | 2 | 1 | 3 | | 2 | 2 | 1 | | 1 | 3 | 1 | +-----------+-------------+---------+ 输入(naiveBayes()X_train)的长度差异需要相同(即x的每一行都有相应的y值)数据)。从

Y_train

我们可以看到输入不同(第1 500和第1 100行X_train <- head(x,500) Y_train <- head(y,100) )。将结果数据从balance_data的相应行分配到Y_train将解决此错误消息。例如,您可以使用:

X_train