【问题标题】:tidy from broom not finding method for LDA from topicmodels从扫帚整理没有从主题模型中找到 LDA 的方法
【发布时间】:2018-07-16 05:51:13
【问题描述】:

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

library(topicmodels)
library(broom)

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

我收到此错误消息:

as.data.frame.default(x) 中的错误: 不能强制类“结构(“LDA_VEM”,包=“主题模型”)”到>data.frame 另外:警告信息: 在 tidy.default(ap_lda) 中: 没有使用 as.data.frame 整理 LDA_VEM 类的 S3 对象的方法

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(内部版本 9200)

矩阵产品:默认

附加的基础包: [1] stats graphics grDevices utils datasets methods base

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

通过命名空间加载(未附加): [1] NLP_0.1-11 Rcpp_0.12.15 compiler_3.4.3pillar_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]网状_1.4胶_1.2.0 R6_2.2.2洋_0.8-69 tidyr_0.8.0
[31] purrr_0.2.4 reshape2_1.4.3 magrittr_1.5 晶须_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

【问题讨论】:

    标签: r broom topicmodels


    【解决方案1】:

    tidytextpackage 似乎扩展了broom package 中使用的一些方法...

    所以使用tidytext 中的tidy 函数确实有效:

    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
    

    当我加载 tidytext : library(tidytext) 后,它会自动为我工作而无需指定 .i.e. tidy(ap_lda, ...)。我可以从你的会话信息中看到 tidytext 没有加载。

    【讨论】:

    • 谢谢斯蒂芬!奇怪的是,我做这个reprex的情况确实有tidytext,然后我仍然得到错误。
    猜你喜欢
    • 2021-05-12
    • 2015-11-15
    • 1970-01-01
    • 2012-03-25
    • 1970-01-01
    • 2023-04-06
    • 2018-09-11
    • 2020-11-23
    • 2015-10-25
    相关资源
    最近更新 更多