1
我使用LDA爲2個文本文檔建立主題模型,稱爲A和B.文檔A與計算機科學高度相關,文檔B與地理科學高度相關。然後我訓練使用此命令的LDA:R主題建模:lda模型標註功能
text<- c(A,B) # introduced above
r <- Corpus(VectorSource(text)) # create corpus object
r <- tm_map(r, tolower) # convert all text to lower case
r <- tm_map(r, removePunctuation)
r <- tm_map(r, removeNumbers)
r <- tm_map(r, removeWords, stopwords("english"))
r.dtm <- TermDocumentMatrix(r, control = list(minWordLength = 3))
my_lda <- LDA(r.dtm,2)
現在我想用my_lda預測新文檔的上下文中說,C和我想看看它是否涉及計算機科學或地理科學。我知道如果我使用此代碼進行預測
x<-C# a new document (a long string) introduced above for prediction
rp <- Corpus(VectorSource(x)) # create corpus object
rp <- tm_map(rp, tolower) # convert all text to lower case
rp <- tm_map(rp, removePunctuation)
rp <- tm_map(rp, removeNumbers)
rp <- tm_map(rp, removeWords, stopwords("english"))
rp.dtm <- TermDocumentMatrix(rp, control = list(minWordLength = 3))
test.topics <- posterior(my_lda,rp.dtm)
它將給我一個標籤1或2,我沒有任何想法是什麼1或2代表......我怎樣才能實現,如果它意味着計算機科學相關或地理科學相關?
你使用什麼軟件包? – Carson 2013-05-06 14:47:12
tm和topicmodels – 2013-05-06 19:44:07