扫帚整理不从主题模型中找到LDA的方法 [英] tidy from broom not finding method for LDA from topicmodels

查看:124
本文介绍了扫帚整理不从主题模型中找到LDA的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

直接从使用R进行文本挖掘中运行此脚本,

  library(topicmodels)
库(扫帚)

data( AssociatedPress)
ap_lda<-LDA(AssociatedPress,k = 2,控件=列表(种子= 1234))
整洁(ap_lda)

我收到此错误消息:


as.data.frame.default(x)中的错误:
无法将类 structure( LDA_VEM,package = topicmodels)强制转换为> data.frame
另外:警告消息:
在tidy.default(ap_lda)中:
没有用于整理类LDA_VEM的S3对象的方法,使用as.data.frame




  packageVersion( broom)




'0.4.3'




  packageVersion( topicmodels)




'0.2.7'




  sessionInfo()

R版本3.4.3(2017-11-30)
平台:x86_64-w64-mingw32 / x64(64位)
运行在:Windows> = 8 x64(build 9200)



矩阵产品:默认



附加的基本软件包:
[1]统计图形grDevices utils数据集方法base



其他附加软件包:
[1] broom_0.4.3 topicmodels_0.2-7



通过a加载命名空间(且未附加):
[1] NLP_0.1-11 Rcpp_0.12.15编辑器_3.4.3支柱_1.1.0 plyr_1.8.4

[6] bindr_0.1 base64enc_0.1-3 keras_2 .1.3 tools_3.4.3 zeallot_0.1.0

[11] jsonlite_1.5 tibble_1.4.2 nlme_3.1-131点阵_0.20-35 pkgconfig_2.0.1

[16] rlang_0.1.6 psych_1.7.8 yaml_2.1.16 parallel_3.4.3 bindrcpp_0.2

[21] stringr_1.2.0 dplyr_0.7.4 xml2_1.2.0 stats4_3.4.3 grid_3.4.3

[26] reticulate_1.4胶_1.2.0 R6_2.2.2 fo reign_0.8-69 tidyr_0.8.0

[31] purrr_0.2.4 reshape2_1.4.3 magrittr_1.5 whisker_0.3-2 tfruns_1.2

[36] modeltools_0.2-21断言_0.2.0 mnormt_1.5-5 tensorflow_1.5 stringi_1.1.6

[41] slam_0.1-42 tm_0.7-3

解决方案

tidytext 软件包似乎正在扩展扫帚中使用的某些方法。包...



因此,请使用 tidytext tidy 函数c>确实起作用:

  b帚:: tidy(ap_lda,matrix = beta)

as.data.frame.default(x)中的错误:
无法将类 structure( LDA_VEM,package = topicmodels)强制转换为data.frame
另外:警告消息:
在tidy.default(ap_lda,matrix = beta)中:
没有使用as.data.frame

tidytext :: tidy来整理LDA_VEM类的S3对象的方法。 (ap_lda,矩阵= beta)

#小标题:20,946 x 3
主题词beta
< int> < chr> < dbl>
1 1 aaron 0.00000000000169
2 2 aaron 0.0000390
3 1放弃0.0000265
4 2放弃0.0000399
5 1放弃0.000139
6 2放弃0.0000588
7 1放弃0.00000000000000000000000000000000245
8 2放弃0.0000234
9 1 abbott 0.00000213
10 2 abbott 0.0000297
#...还有20,936行

当我加载 tidytext 时: library(tidytext) ,则无需指定.ie即可自动为我工作 tidy(ap_lda,...)。我从您的会话信息中看到, tidytext 未加载。


Running this script, straight from 'Text mining with R',

library(topicmodels)
library(broom)

data("AssociatedPress")
ap_lda <- LDA(AssociatedPress, k = 2, control = list(seed = 1234))
tidy(ap_lda)

I get this error message:

Error in as.data.frame.default(x) : cannot coerce class "structure("LDA_VEM", package = "topicmodels")" to a >data.frame In addition: Warning message: In tidy.default(ap_lda) : No method for tidying an S3 object of class LDA_VEM , using as.data.frame

packageVersion("broom")

‘0.4.3’

packageVersion("topicmodels")

‘0.2.7’

sessionInfo()

R version 3.4.3 (2017-11-30) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] broom_0.4.3 topicmodels_0.2-7

loaded via a namespace (and not attached): [1] NLP_0.1-11 Rcpp_0.12.15 compiler_3.4.3 pillar_1.1.0 plyr_1.8.4
[6] bindr_0.1 base64enc_0.1-3 keras_2.1.3 tools_3.4.3 zeallot_0.1.0
[11] jsonlite_1.5 tibble_1.4.2 nlme_3.1-131 lattice_0.20-35 pkgconfig_2.0.1
[16] rlang_0.1.6 psych_1.7.8 yaml_2.1.16 parallel_3.4.3 bindrcpp_0.2
[21] stringr_1.2.0 dplyr_0.7.4 xml2_1.2.0 stats4_3.4.3 grid_3.4.3
[26] reticulate_1.4 glue_1.2.0 R6_2.2.2 foreign_0.8-69 tidyr_0.8.0
[31] purrr_0.2.4 reshape2_1.4.3 magrittr_1.5 whisker_0.3-2 tfruns_1.2
[36] modeltools_0.2-21 assertthat_0.2.0 mnormt_1.5-5 tensorflow_1.5 stringi_1.1.6
[41] slam_0.1-42 tm_0.7-3

解决方案

The tidytextpackage appears to be extending some of the methods used in the broom package...

So using the tidy function from tidytext does work:

broom::tidy(ap_lda, matrix = "beta")

Error in as.data.frame.default(x) : 
  cannot coerce class "structure("LDA_VEM", package = "topicmodels")" to a data.frame
In addition: Warning message:
In tidy.default(ap_lda, matrix = "beta") :
  No method for tidying an S3 object of class LDA_VEM , using as.data.frame

tidytext::tidy(ap_lda, matrix = "beta")

# A tibble: 20,946 x 3
   topic term                                        beta
   <int> <chr>                                      <dbl>
 1     1 aaron      0.00000000000169                     
 2     2 aaron      0.0000390                            
 3     1 abandon    0.0000265                            
 4     2 abandon    0.0000399                            
 5     1 abandoned  0.000139                             
 6     2 abandoned  0.0000588                            
 7     1 abandoning 0.00000000000000000000000000000000245
 8     2 abandoning 0.0000234                            
 9     1 abbott     0.00000213                           
10     2 abbott     0.0000297                            
# ... with 20,936 more rows

When I have loaded tidytext : library(tidytext) then this works automatically for me without specifying .i.e. tidy(ap_lda, ...). I can see from your session info that tidytext is not loaded.

这篇关于扫帚整理不从主题模型中找到LDA的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆