我们可以将 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
如果您使用 topicmodels 包浏览 LDA 主题建模的文档,例如通过?LDA
在 R 控制台中键入,您将看到此建模过程需要频率加权的文档项矩阵,而不是 tf-idf 加权。
"Object of class "DocumentTermMatrix" with term-frequency weighting or an object coercible..."
所以答案是否定的,你不能在这个函数中直接使用 tf-idf-weighted DTM。如果您已经有一个 tf-idf-weighted DTM,您可以使用它来转换它tm::weightTf()
以获得必要的权重。如果您从头开始构建文档术语矩阵,则不要通过 tf-idf 对其进行加权。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句