4
我試圖運行使用topicmodels包R.手冊中給出的示例的LDA使用美聯社的數據和很好地工作。但是,當我嘗試使用自己的數據時,我得到的主題是文檔名稱。我已經查明問題的事實,我的單詞文書矩陣的方式轉置應爲(行 - >列)。Topicmodels調換術語文檔矩陣
的例子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)
任何幫助,將不勝感激。
是的,就是這樣。謝謝!我還發現,矩陣轉置函數't()'也適用於這個類,並獲得相同的結果。 – cjbayesian
我想知道如何使用't()'。但是,我無法在包:: tm中找到'AssociatedPress'。 –
我發現t()也可以。 – cjbayesian