0
저는 94 개의 텍스트를 분류하려고합니다. trainset의 범주가 testset의 범주에 존재하지 않으면 naiveBayes가 제대로 작동하지 않으므로 무작위로 확인했습니다. 카테고리에 문제가 없었습니다. 그러나 분류 기준은 testset에서 작동하지 않았습니다. 이 분류는 잘 작동R에서의 순진 베이 오류 : 아래 첨자가 범위를 벗어났습니다
Df.dtm<-cbind(Df.dtm, category)
dim(Df.dtm)
Df.dtm[1:10, 530:532]
# Randomize and Split data by rownumber
train <- sample(nrow(Df.dtm), ceiling(nrow(Df.dtm) * .50))
test <- (1:nrow(Df.dtm))[- train]
# Isolate classifier
cl <- Df.dtm[, "category"]
> summary(cl[train])
dip eds ind pols
23 8 3 13
# Create model data and remove "category"
modeldata <- Df.dtm[,!colnames(Df.dtm) %in% "category"]
#Boolean feature Multinomial Naive Bayes
#Function to convert the word frequencies to yes and no labels
convert_count <- function(x) {
y <- ifelse(x > 0, 1,0)
y <- factor(y, levels=c(0,1), labels=c("No", "Yes"))
y
}
#Apply the convert_count function to get final training and testing DTMs
train.cc <- apply(modeldata[train, ], 2, convert_count)
test.cc <- apply(modeldata[test, ], 2, convert_count)
#Training the Naive Bayes Model
#Train the classifier
system.time(classifier <- naiveBayes(train.cc, cl[train], laplace = 1))
: 이 流逝
#Use the classifier we built to make predictions on the test set.
system.time(pred <- predict(classifier, newdata=test.cc))
0.45 0.00 0.46
그러나, 예측이 실패 系统 用户 다음 는 오류 메시지입니다. 오류[.default
에서 (객체 $ 테이블은 [[V], 차이) : 0.2 0 0.2