Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
556 views
in Technique[技术] by (71.8m points)

naivebayes - Advice for Naive Bayes in R

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...