簡體   English   中英

執行困惑度函數評估LDA模型時出錯

[英]Getting an error while executing perplexity function to evaluate the LDA model

我正在嘗試評估主題建模(LDA)。 執行困惑性函數時遇到錯誤,例如:錯誤(函數(類,fdef,mtable):無法為簽名“ LDA_Gibbs”,“數字”找到函數“困惑性”的繼承方法,請幫助解決此問題。

由於您未提供任何代碼示例,因此很難知道確切的問題是什么。 但是,當我遇到相同的錯誤時,我發現了這個問題,因此我將在此提供我遇到的問題和解決方案,以希望它可以對其他人有所幫助。

topicmodels包,配件在使用吉布斯的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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM