为什么我会收到此错误?什么是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
整个代码
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
答案 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