[英]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.