如何使用LDA包绘制R中每次迭代的log.likelihoods?

时间:2015-05-20 18:53:37

标签: r lda topic-modeling

我的问题是我想使用LDA包在R中绘制从LDA执行中收集的log.likelihoods。我的代码是:

K <- 10 ## Num clusters
result <- lda.collapsed.gibbs.sampler(cora.documents,
                                      K,  ## Num clusters
                                      cora.vocab,
                                      25,  ## Num iterations
                                      0.1,
                                      0.1,
                                      compute.log.likelihood=TRUE) 

1 个答案:

答案 0 :(得分:0)

我找到了解决方案:

df<-data.frame(topics=c(1:100), LL=as.numeric(as.matrix(result$log.likelihood[1,])))
ggplot(df, aes(x=topics, y=LL)) + 
xlab("iteration") + ylab("Log likelihood of the model") + 
geom_line() + 
theme_bw()  + 
theme(axis.title.x = element_text(vjust = -0.25, size = 14)) + 
theme(axis.title.y = element_text(size = 14, angle=90))