主题是 TermDocumentMatrix 的术语(=单词)的多项分布。使用以 k=5
作为主题数量的标准数据集...
library(topicmodels)
data("AssociatedPress", package = "topicmodels")
k <- 5
lda <- LDA(AssociatedPress[1:20,], control = list(alpha = 0.1), k)
str(lda)
给出以下输出
Formal class 'LDA_VEM' [package "topicmodels"] with 14 slots
..@ alpha : num 0.0184
..@ call : language LDA(x = AssociatedPress[1:20, ], k = k, control = list(alpha = 0.1))
..@ Dim : int [1:2] 20 10473
..@ control :Formal class 'LDA_VEMcontrol' [package "topicmodels"] with 13 slots
.. .. ..@ estimate.alpha: logi TRUE
.. .. ..@ alpha : num 0.1
.. .. ..@ seed : int 1437208609
.. .. ..@ verbose : int 0
.. .. ..@ prefix : chr
.. .. ..@ save : int 0
.. .. ..@ nstart : int 1
.. .. ..@ best : logi TRUE
.. .. ..@ keep : int 0
.. .. ..@ estimate.beta : logi TRUE
.. .. ..@ var :Formal class 'OPTcontrol' [package "topicmodels"] with 2 slots
.. .. .. .. ..@ iter.max: int 500
.. .. .. .. ..@ tol : num 1e-06
.. .. ..@ em :Formal class 'OPTcontrol' [package "topicmodels"] with 2 slots
.. .. .. .. ..@ iter.max: int 1000
.. .. .. .. ..@ tol : num 1e-04
.. .. ..@ initialize : chr "random"
..@ k : int 5
..@ terms : chr [1:10473] "aaron" "abandon" "abandoned" "abandoning" ...
..@ documents : NULL
..@ beta : num [1:5, 1:10473] -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 ...
..@ gamma : num [1:20, 1:5] 7.00e-05 6.79e-05 7.22e-05 8.89e-05 2.79e-04 ...
..@ wordassignments:List of 5
.. ..$ i : int [1:2533] 1 1 1 1 1 1 1 1 1 1 ...
.. ..$ j : int [1:2533] 116 153 218 272 299 302 447 455 548 597 ...
.. ..$ v : num [1:2533] 5 5 5 5 5 5 5 5 5 5 ...
.. ..$ nrow: int 20
.. ..$ ncol: int 10473
.. ..- attr(*, "class")= chr "simple_triplet_matrix"
..@ loglikelihood : num [1:20] -1512 -1584 -1400 -1324 -418 ...
..@ iter : int 12
..@ logLiks : num(0)
..@ n : int 3636
lda
中似乎没有对象存储我需要的数据。我知道 gamma
给出了主题在文档上的分布,但是我如何访问主题在术语上的分布?
最佳答案
您可以使用 posterior(lda)$terms
查看主题相对术语的后验分布。
library(topicmodels)
data("AssociatedPress", package = "topicmodels")
lda <- LDA(AssociatedPress[1:20,], control = list(alpha = 0.1), k = 2)
terms <- as.data.frame(t(posterior(lda)$terms))
head(terms)
1 2
aaron 3.720076e-44 3.720076e-44
abandon 3.720076e-44 3.720076e-44
abandoned 3.720076e-44 3.720076e-44
abandoning 3.720076e-44 3.720076e-44
abbott 3.720076e-44 3.720076e-44
abboud 3.720076e-44 3.720076e-44
关于R:LDA Topicmodels - 术语的分布在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31489489/