首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >R topicmodels tidytext -潜伏的小波分配(LDA):错误:找不到绑定:'Var1‘

R topicmodels tidytext -潜伏的小波分配(LDA):错误:找不到绑定:'Var1‘
EN

Stack Overflow用户
提问于 2017-04-21 05:31:35
回答 1查看 393关注 0票数 0

我在R中的LDA模型有问题。每次我试图在我的LDA_VEM对象上执行my ()函数时,我得到一个错误:" error : binding not found:'Var1‘。你能解释一下如何解决这个问题吗?我的代码如下:

代码语言:javascript
复制
why <-read.csv("FakeDoc.csv", header = FALSE, na.strings = "")
why.char <- data_frame(text=as.character(why$V1))
why.char <- why.char %>%
  mutate(document = row_number())
why.tidy <- why.char %>%
  unnest_tokens(word, text)
why.tidy <- why.tidy %>%
  anti_join(stop_words)
why.tidy <- why.tidy %>%
  filter(!str_detect(word,"[0-9]"))

  #Frequency Table
why.doc <- why.tidy %>%
  count(document, word, sort = TRUE) %>%
  ungroup()
why.words <- why.doc %>%
  group_by(document) %>%
  summarize(total = sum(n))
why.ft <- left_join(why.doc, why.words)
grams1_united <- why.ft[c("document", "word", "total")] 

  #N-grams
tidy.n2 <- why.char %>%
  unnest_tokens(ngram, text, token = "ngrams", n=2)
tidy.n3 <- why.char %>%
  unnest_tokens(ngram, text, token = "ngrams", n=3)

tidy.n2 <- tidy.n2 %>%
  filter(!str_detect(ngram, "[0-9]"))
tidy.n3 <- tidy.n3 %>%
  filter(!str_detect(ngram, "[0-9]"))

tidy.n2 %>%
  count(ngram, sort = TRUE)
tidy.n3 %>%
  count(ngram, sort = TRUE)

grams2_seperated <- tidy.n2 %>%
  separate(ngram, c("word1", "word2"), sep = " ")
grams2_filtered <- grams2_seperated %>%
  filter(!word1 %in% stop_words$word) %>%
  filter(!word2 %in% stop_words$word)
gram2_counts <- grams2_filtered %>%
  count(word1, word2, sort = TRUE)
grams2_united <- grams2_filtered %>%
  unite(ngram, word1, word2, sep = " ")
grams2_united <- grams2_united %>%
  group_by(document) %>%
  count(ngram, sort = TRUE)
grams2_united

grams3_seperated <- tidy.n3 %>%
  separate(ngram, c("word1", "word2", "word3"), sep = " ")
grams3_filtered <- grams3_seperated %>%
  filter(!word1 %in% stop_words$word) %>%
  filter(!word2 %in% stop_words$word) %>%
  filter(!word3 %in% stop_words$word)
gram3_counts <- grams3_filtered %>%
  count(word1, word2, word3, sort = TRUE)
grams3_united <- grams3_filtered %>%
  unite(ngram, word1, word2, word3, sep = " ")
grams3_united <- grams3_united %>%
  group_by(document) %>%
  count(ngram, sort = TRUE)

colnames(grams2_united) <- c("document", "word", "total")
colnames(grams3_united) <- c("document", "word", "total")

  #DTM
grams1_united
grams2_united
grams3_united
detractorwhy.tots <- rbind.data.frame(grams1_united, grams2_united, grams3_united)
dtwtots <- as.data.frame(detractorwhy.tots)
dtw.dtm <- dtwtots %>%
  cast_dtm(document, word, total)
dtw_5lda <- LDA(dtw.dtm,control = list(alpha = 0.05), k = 5)
topics <- tidy(dtw_5lda)
EN

回答 1

Stack Overflow用户

发布于 2019-10-03 23:13:50

在LDA对象上运行tidy时出现相同的错误。最终,我发现我加载的库之间存在某种冲突: topicmodels和reshape2。在我停止导入reshape2库后,错误消失了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43530272

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档