【问题标题】:Getting an error while executing perplexity function to evaluate the LDA model执行困惑函数评估 LDA 模型时出错
【发布时间】:2018-07-28 00:03:50
【问题描述】:

我正在尝试评估主题建模 (LDA)。执行困惑函数时出现错误:(函数(类,fdef,mtable)中的错误:无法为签名“LDA_Gibbs”,“numeric”的函数“困惑”找到继承的方法有人请帮助解决这个问题。

【问题讨论】:

    标签: text lda topic-modeling perplexity


    【解决方案1】:

    由于您没有提供任何代码示例,因此很难知道您的确切问题是什么。但是,当我遇到同样的错误时,我发现了这个问题,所以我将在这里提供我遇到的问题和解决方案,希望它可以帮助其他人。

    topicmodels 包中,当使用 Gibbs 进行拟合时,perplexity() 函数需要以文档术语格式提供 newdata。如果你给它别的东西,你会得到这个错误。根据您的错误消息,您可能给了它 numeric 而不是 dtm。

    这是一个工作示例,使用来自 lda 包的新闻组数据转换为 dtm 格式:

    library(topicmodels)
    
    # load the required data from lda package
    data("newsgroup.train.documents", "newsgroup.test.documents", "newsgroup.vocab", package="lda")
    
    
    # create document-term matrix using newsgroups training data
    dtm <- ldaformat2dtm(documents = newsgroup.train.documents, vocab = newsgroup.vocab)
    
    # fit LDA model using Gibbs sampler
    fit <- LDA(x = dtm, k = 20, method="Gibbs")
    
    # create document-term matrix using newsgroups test data
    testdtm <- ldaformat2dtm(documents = newsgroup.test.documents, vocab = newsgroup.vocab)
    
    # calculate perplexity
    perplexity(fit, newdata = testdtm)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-08-16
      • 1970-01-01
      • 2017-09-20
      • 2018-03-12
      • 1970-01-01
      • 1970-01-01
      • 2010-10-01
      • 2014-04-26
      相关资源
      最近更新 更多