I creating a code to compare tweets of two different politicians. I have created a master corpus containing them both. I am using the Naive Bayes method. I keep getting the same error message and I don't know how to fit this, I will show the code below. Any advice would be appreciated! Thanks
set.seed(300)
id_train <- sample(1:5000, 1500, replace = FALSE)
head(id_train, 10)
MasterCorpus$id_numeric <- 1:ndoc(MasterCorpus)
dfmat_training <- corpus_subset(MasterCorpus, id_numeric %in% id_train) %>%
dfm(remove = stopwords("en"), stem = TRUE)
dfmat_test <- corpus_subset(MasterCorpus, !id_numeric %in% id_train) %>%
dfm(remove = stopwords("english"), stem = TRUE)
tmod_nb <- textmodel_nb(dfmat_training, dfmat_training$author)
However, after the last line of code, I keep getting this error message:
tmod_nb <- textmodel_nb(dfmat_training, dfmat_training$author)
Error in if (stats::var(as.numeric(y), na.rm = TRUE) == 0) stop("y cannot be constant") :
missing value where TRUE/FALSE needed
question from:
https://stackoverflow.com/questions/65869953/advice-for-naive-bayes-in-r 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…