4

我正在尝试使用 R 中的 topicmodels 包运行 LDA。手册中给出的示例使用美联社数据并且运行良好。但是,当我在自己的数据上尝试它时,我会得到术语是文档名称的主题。我已经将问题追溯到我的术语文档矩阵是应该的方式的转置(行->列)。

示例 TDM:

str(AssociatedPress)
List of 6
$ i       : int [1:302031] 1 1 1 1 1 1 1 1 1 1 ...

$ j       : int [1:302031] 116 153 218 272 299 302 447 455 548 597 ...
$ v       : int [1:302031] 1 2 1 1 1 1 2 1 1 1 ...
$ nrow    : int 2246
$ ncol    : int 10473
$ dimnames:List of 2
..$ Docs : NULL
..$ Terms: chr [1:10473] "aaron" "abandon" "abandoned" "abandoning" ...
- attr(*, "Weighting")= chr [1:2] "term frequency" "tf"
- attr(*, "class")= chr [1:2] "DocumentTermMatrix" "simple_triplet_matrix"

鉴于,我的 TDM 将术语作为行,将文档作为列:

List of 6
$ i       : int [1:10489] 1 3 4 13 20 24 25 26 27 28 ...
$ j       : int [1:10489] 1 1 1 1 1 1 1 1 1 1 ...
$ v       : num [1:10489] 1 1 1 1 2 1 67 1 44 3 ...
$ nrow    : int 5903
$ ncol    : int 9
$ dimnames:List of 2
..$ Terms: chr [1:5903] "\u2439aa" "aars" "\u2439ab" "\u242dab" ...
..$ Docs : chr [1:9] "art111130.txt" "art111131.txt" "art111132.txt" "art111133.txt" ...
- attr(*, "class")= chr [1:2] "TermDocumentMatrix" "simple_triplet_matrix"
- attr(*, "Weighting")= chr [1:2] "term frequency" "tf"

这导致LDA(art_tdm,3)基于文档名称而不是文档中的术语构建主题。这是 tm 包的代码库的变化吗?我无法想象我会做什么来在我的代码中导致这种转置:

art_cor<-Corpus(DirSource(directory = "tmptxts"))
art_tdm<-TermDocumentMatrix(art_cor)

任何帮助,将不胜感激。

4

1 回答 1

3

一方面你有一个“TermDocumentMatrix”类的对象,另一方面你有一个“DocumentTermMatrix”。

你可能只需要这样做:

art_tdm<-DocumentTermMatrix(art_cor)
于 2012-10-20T20:15:07.043 回答