我正在尝试使用naivebays分类器实现分类器算法。但是收到错误 -
表格中的错误(y,var):所有参数必须具有相同的长度
使用命令
sms_classifier< - naiveBayes(sms_train,sms_raw_train $ type)
目前执行的命令列表 -
sms_dtm <- TermDocumentMatrix(corpus_clean)
sms_dtm_train <- sms_dtm[1:39,]
sms_dtm_test <- sms_dtm[40:59,]
sms_corpus_train <- corpus_clean[1:39]
sms_corpus_test <- corpus_clean[40:59]
table(sms_raw$type)
table(sms_raw_train$type)
table(sms_raw_test$type)
sms_dict <- Dictionary(findFreqTerms(sms_dtm_train,5))
sms_train <- TermDocumentMatrix(sms_corpus_train, control = list(minDocFreq=5,minWordLength=1))
str(sms_train)
sms_test <- TermDocumentMatrix(sms_corpus_test, control = list(minDocFreq=5,minWordLength=1))
convert_count <- function(x){
x <- ifelse(x>0,1,0)
x <- factor(x, levels = c(0,1), labels = c("No","Yes"))
return(x)
}
sms_train <- apply(sms_train,MARGIN = 2, convert_count)
sms_test <- apply(sms_test, MARGIN = 2, convert_count)
library(e1071)
sms_classifier <- naiveBayes(sms_train, sms_raw_train$type)
此致 阿米特