Help with Naïve Bayes Analysis in R

Hi,
I am trying to analyse some tweets using the naive bayes method on R. However, I am having issues, below is my code. When I try and produce a text model, I keep getting told that y cannot be constant. I am not clear what this error message means or how to solve it.

Help would be much appreciated.

Thanks!

set.seed(300)
id_train <- sample(1:5000, 1500, replace = FALSE)
head(id_train, 10)
[1] 2638 874 3650 3740 789 553 1705 4368 4557
[10] 2828
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)
Error in textmodel_nb.dfm(dfmat_training, dfmat_training$author) :
y cannot be constant

How many authors are there in training?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

There are only two authors