【问题标题】:Tidy doesn't work, gives this error : No tidy method for objects of class LDA_GibbsTidy 不起作用,出现此错误:No tidy method for objects of class LDA_Gibbs
【发布时间】:2018-09-12 07:55:57
【问题描述】:

此代码显示错误:错误:LDA_Gibbs 类的对象没有整洁的方法

我不明白为什么.....每当我尝试做 test_lda_td2

library(NLP)
library(tm)
library(tidytext)
library(stringr)
library(tidyr)
library(topicmodels)
library(tidyverse)

mywords<- read.csv("mystop.csv",header =F,sep = ",")
mywords <- as.character(mywords)
mywords <- c(mywords, stopwords())

filelist = list.files(pattern = ".*.txt")
files <- lapply(filelist,readLines)

(docs <- VCorpus(VectorSource(files)))

docs <-tm_map(docs,content_transformer(tolower))
docs <- tm_map(docs, removePunctuation)
docs <- tm_map(docs, removeNumbers)
docs <- tm_map(docs, removeWords, mywords)

docs <- tm_map(docs, removeWords,stopwords("english"))
docs <- tm_map(docs, stripWhitespace)

toSpace <- content_transformer(function(x, pattern) { return (gsub(pattern, 
" " , x))})
docs <- tm_map(docs, toSpace, "-")
docs <- tm_map(docs, toSpace, "’")
docs <- tm_map(docs, toSpace, "‘")
docs <- tm_map(docs, toSpace, "•")
docs <- tm_map(docs, toSpace, "”")
docs <- tm_map(docs, toSpace, "“")

#...............
dtm <- DocumentTermMatrix(docs)
rownames(dtm) <- filelist
freq <- colSums(as.matrix(dtm))
length(freq)
ord <- order(freq,decreasing=TRUE)

d <- data.frame(word = names(freq),freq=freq[ord])

new_dtm<-dtm

burnin <- 4000
iter <- 2000
thin <- 500
seed <-list(2003,5,63,100001,765)
nstart <- 5
best <- TRUE
k <- 3
test_lda2 <-LDA(new_dtm,k, method="Gibbs",
control=list(nstart=nstart, seed = seed, best=best,
burnin = burnin, iter = iter, thin=thin))

test_lda_td2 <- tidy(test_lda2) <---Error

lda_top_terms2 <- test_lda_td2 %>%
group_by(topic) %>%
top_n(10, beta) %>%
ungroup() %>%
arrange(topic, -beta)

lda_top_terms2 %>%
mutate(term = reorder(term, beta)) %>%
ggplot(aes(term, beta, fill = factor(topic))) +
geom_bar(stat = "identity", show.legend = FALSE) +
facet_wrap(~ topic, scales = "free") +
coord_flip()

【问题讨论】:

  • 欢迎来到 SO!如果您能够减少代码并提供更具重现性的示例,您可能会得到更多的响应。对于前者,滚动代码页面可能是一种威慑,尤其是当很明显不需要重现问题/错误的大部分代码时。关于如何提出一个好的和小的可重现问题的好参考:stackoverflow.com/questions/5963269stackoverflow.com/help/mcvestackoverflow.com/tags/r/info
  • 你真的读过这个错误吗? topicmodels::LDA 没有整洁的方法。看扫帚available methods vignette,看看扫帚可以整理哪些方法。
  • 感谢您的帮助@phiver

标签: r tidyverse lda topic-modeling tidy


【解决方案1】:

多个包中可能存在同名的函数。而且,您在“library()”中调用的最新一个优先。建议尝试使用包名调用该函数并检查是否仍然出现错误。

.()

例如:- tidyr.tydy()

【讨论】:

    猜你喜欢
    • 2018-07-28
    • 2018-08-16
    • 1970-01-01
    • 2014-02-21
    • 2018-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-19
    相关资源
    最近更新 更多