row_sums vs findfreqterms用于子集termdocmatrix以包含具有给定最小频率的单词
我的问题很简单。我有一个(二进制)TDM,我想减少至少两个文档中出现的行的行数:
我认为这两种方法会在二进制矩阵中产生相同的结果:
> rowTotals = row_sums(tdm)
> dtm2 <- tdm[which(rowTotals > 2),]
> dtm2
<<TermDocumentMatrix (terms: 208361, documents: 763717)>>
Non-/sparse entries: 34812736/159094025101
Sparsity : 100%
Maximal term length: 154
Weighting : binary (bin)
> #alternative probably faster:
> atleast2 <- findFreqTerms(tdm, lowfreq = 2)
> dtm2 <- tdm[atleast2,]
> dtm2
<<TermDocumentMatrix (terms: 340436, documents: 763717)>>
Non-/sparse entries: 35076886/259961683726
Sparsity : 100%
Maximal term length: 308
Weighting : binary (bin)
但是事实并非如此..您能帮助弄清楚为什么不是吗?
my question is straightforward. I have a (binary) TDM and I want to reduce the number of rows to include only those rows that appear in at least two documents:
I thought that these two methods would produce the same result in a binary matrix:
> rowTotals = row_sums(tdm)
> dtm2 <- tdm[which(rowTotals > 2),]
> dtm2
<<TermDocumentMatrix (terms: 208361, documents: 763717)>>
Non-/sparse entries: 34812736/159094025101
Sparsity : 100%
Maximal term length: 154
Weighting : binary (bin)
> #alternative probably faster:
> atleast2 <- findFreqTerms(tdm, lowfreq = 2)
> dtm2 <- tdm[atleast2,]
> dtm2
<<TermDocumentMatrix (terms: 340436, documents: 763717)>>
Non-/sparse entries: 35076886/259961683726
Sparsity : 100%
Maximal term length: 308
Weighting : binary (bin)
yet it is not so.. Could you help figuring out why it isn't?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它们产生完全相同的结果。您的第二部分有一个错误。您的频率为2及以上,而在第一部分中,您的单词频率为3及以上。如果确保两个选择标准都是相同的,则会发现它们将产生相同的结果。请参见下面的代码示例。也要速度比较。
他们一样吗?
速度:
通过ROW_TOTALS选择的速度稍快。但这是因为
findfreqterms
实际上使用row_sums
获取信息,并且有一些额外的代码行检查是否通过文档术语矩阵,以及您请求的频率是否是实际数字。They produce the exact same result. You have a mistake in your second part. You are taking the frequency of 2 and more, while in the first part you are taking all the words with a frequency of 3 and more. If make sure both selection criteria are the same you will see that they will produce the same result. See code example below. Also speed comparison.
Are they the same?
Speed:
The selection via row_totals is slightly faster. But that is because
findFreqTerms
actually usesrow_sums
to get the info and has some extra lines of code to check if you pass it an document term matrix and if the frequencies you request are actual numbers.