0

I am literally following the steps as presented in chapter 6 of the "Text Mining in R: a Tidy Approach" book. See: https://www.tidytextmining.com/topicmodeling.html

#import libraries
library(topicmodels)
library(tidytext)

#access dataset
data("AssociatedPress")

# set a seed so that the output of the model is predictable
ap_lda <- LDA(AssociatedPress, k = 2, control = list(seed = 1234))

#tidy model object
ap_topics <- tidy(ap_lda, matrix = "beta")

Gives me the following error in the terminal:

Error: No tidy method for objects of class LDA_VEM

What I should be getting, meanwhile is:

## # A tibble: 20,946 x 3
##    topic term           beta
##    <int> <chr>         <dbl>
##  1     1 aaron      1.69e-12
##  2     2 aaron      3.90e- 5
##  3     1 abandon    2.65e- 5
##  4     2 abandon    3.99e- 5
##  5     1 abandoned  1.39e- 4
##  6     2 abandoned  5.88e- 5
##  7     1 abandoning 2.45e-33
##  8     2 abandoning 2.34e- 5
##  9     1 abbott     2.13e- 6
## 10     2 abbott     2.97e- 5
## # ... with 20,936 more rows

Why am I seeing this error instead of the desired result?

4

2 回答 2

1

你不是第一个遇到这个问题的人,但它很难重现。事实上,我个人从未能够重现该错误。但是,我知道这是一个真正的问题,因为……如果您想看到其他人也在苦苦挣扎,请查看此处此处此处此处

据我所知,这可能是 topicmodels 包中的一个错误,与 S4 注册有关。您可以通过不在.RData会话之间保存并在打开工作时始终从新的 R 会话开始来避免遇到这种情况

于 2018-12-12T04:01:58.413 回答
0

您需要首先整理 AssociatedPress 数据。像这样:

#if(!require("topicmodels")) install.packages("topicmodels")
#install.packages("topicmodels")
library(topicmodels)
data("AssociatedPress",package="topicmodels")
AssociatedPress
#Getting the Terms
terms<-Terms(AssociatedPress)
head(terms)
#tidyig with the tidy function
ap_tidy<-tidy(AssociatedPress)

接着:

ap_lda<-LDA(AssociatedPress,k=2,control=list(seed=1234))
ap_topics<-tidy(ap_lda,matrix="beta")
head(ap_topics)

这使:

 topic term          beta
  <int> <chr>        <dbl>
1     1 aaron     1.69e-12
2     2 aaron     3.90e- 5
3     1 abandon   2.65e- 5
4     2 abandon   3.99e- 5
5     1 abandoned 1.39e- 4
6     2 abandoned 5.88e- 5
于 2018-12-11T16:43:20.860 回答