我在两个月前运行了这个主题建模脚本SUCCESSFULLY,但它突然给了我一条错误信息(在最后三行)。
post <- posterior(TM1, newdata = dtm[-c(1:20),]) #this script gives me an error message.
perplex <- perplexity(TM1, newdata = dtm[-c(1:20),]) #this script does not give me an error message.
有人可以帮我解决这里发生的事吗?请~~
=====================
library("tm")
library("slam")
library("topicmodels")
library("SnowballC")
corpus <- Corpus(DirSource(directory="/Users/loni/Documents/TextMining/test", encoding="UTF-8"))
dtm <- DocumentTermMatrix(corpus, control=list(stemming=TRUE, stopwords=TRUE, removePunctuation=FALSE))
term_tfidf <- tapply(dtm$v/row_sums(dtm)[dtm$i], dtm$j, mean) * log2(nDocs(dtm)/col_sums(dtm>0))
dim(dtm)
[1] 26 919
dtm <- dtm[, term_tfidf >= .06] # petition corpus
dtm <- dtm[row_sums(dtm) > 0,]
dim(dtm)
[1] 26 499
k<-5
SEED <- 2
TM <- list(VEM = LDA(dtm, k = k, control = list(seed = SEED)))
TM1 <- list(VEM = LDA(dtm[c(1:20),], k = k, control = list(seed = SEED))) #validation
Topic <- topics(TM[["VEM"]],1)
Terms <- terms(TM[["VEM"]], 8)
Terms[, 1:5]
post <- posterior(TM1, newdata = dtm[-c(1:20),])
(函数(classes,fdef,mtable)中的错误: 无法为签名'“list”,“DocumentTermMatrix”'
找到函数'后验'的继承方法答案 0 :(得分:0)
可能是因为列表索引错误。在TM1上尝试[[]]或[]