【发布时间】:2018-01-15 20:05:44
【问题描述】:
我们可以将 tf-idf 文档术语矩阵输入到潜在狄利克雷分配 (LDA) 中吗?如果是,怎么做?
在我的情况下它不起作用,LDA 函数需要“词频”文档词矩阵。
谢谢
(我尽可能简洁地提出一个问题。所以,如果您需要更多详细信息,我可以添加
##########################################################################
TF-IDF Document matrix construction
##########################################################################
> DTM_tfidf <-DocumentTermMatrix(corpora,control = list(weighting =
function(x)+ weightTfIdf(x, normalize = FALSE)))
> str(DTM_tfidf)
List of 6
$ i : int [1:4466] 1 1 1 1 1 1 1 1 1 1 ...
$ j : int [1:4466] 6 10 22 26 28 36 39 41 47 48 ...
$ v : num [1:4466] 6 2.09 1.05 3.19 2.19 ...
$ nrow : int 64
$ ncol : int 297
$ dimnames:List of 2
..$ Docs : chr [1:64] "1" "2" "3" "4" ...
..$ Terms: chr [1:297] "accommod" "account" "achiev" "act" ...
- attr(*, "class")= chr [1:2] "DocumentTermMatrix" "simple_triplet_matrix"
- attr(*, "weighting")= chr [1:2] "term frequency - inverse document
frequency" "tf-idf"
##########################################################################
LDA section
##########################################################################
> LDA_results <-LDA(DTM_tfidf,k, method="Gibbs", control=list(nstart=nstart,
+ seed = seed, best=best,
+ burnin = burnin, iter = iter, thin=thin))
##########################################################################
Error messages
##########################################################################
Error in LDA(DTM_tfidf, k, method = "Gibbs", control = list(nstart =
nstart, :
The DocumentTermMatrix needs to have a term frequency weighting
【问题讨论】:
-
最好提供一个可重现的最小示例。您可以通过使用虚拟数据集或软件包附带的示例数据集来做到这一点。 (参见例如我的最后一个答案。)
标签: r matrix text-mining lda tidytext