[英]Getting an error while executing perplexity function to evaluate the LDA model
I am trying to evaluate the topic modeling(LDA). 我正在尝试评估主题建模(LDA)。 Getting a error while execting perplexity function as: Error in (function (classes, fdef, mtable) : unable to find an inherited method for function 'perplexity' for signature '"LDA_Gibbs", "numeric"' someone please help to solve this. 执行困惑性函数时遇到错误,例如:错误(函数(类,fdef,mtable):无法为签名“ LDA_Gibbs”,“数字”找到函数“困惑性”的继承方法,请帮助解决此问题。
As you haven't provided any example of your code, it's difficult to know what your exact issue is. 由于您未提供任何代码示例,因此很难知道确切的问题是什么。 However, I found this question when I was facing the same error so I will provide the problem I faced and solution here in the hope that it may help someone else. 但是,当我遇到相同的错误时,我发现了这个问题,因此我将在此提供我遇到的问题和解决方案,以希望它可以对其他人有所帮助。
In the topicmodels
package, when fitting using Gibbs the perplexity()
function requires newdata
to be supplied in a document-term format. 在topicmodels
包,配件在使用吉布斯的perplexity()
函数需要newdata
在文档术语格式来提供。 If you give it something else, you get this error. 如果您给它其他东西,则会出现此错误。 Going by your error message you were probably giving it something numeric
instead of a dtm. 根据您的错误消息,您可能会给它一些numeric
而不是dtm。
Here is a working example, using the newsgroups data from the lda
package converted to the dtm format: 这是一个工作示例,使用来自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.