【问题标题】:Why does the output differ for tm package and RTextTools package?为什么 tm 包和 RTextTools 包的输出不同?
【发布时间】:2017-12-10 11:07:58
【问题描述】:

我有一个包含 260 个 RTI 应用程序的数据集。我应该对他们执行LDA。我已经使用 tm 以及 RTextTools 包创建了 term-doc 矩阵。但是,输出差异很大。 Tm 包不显示任何稀疏条目计数。总术语的数量差异很大。 代码如下:

library("tm")
library("RTextTools")
<I read the data here into a variable called 'data'>
doc = Corpus(VectorSource(data))
m = create_matrix(data, language = "english", removeNumbers = TRUE, removePunctuation = TRUE, stemWords = TRUE, weighting = weightTf) #RtextTools statement
tdm <- TermDocumentMatrix(doc, control = list(removePunctuation = TRUE, removeNumbers = TRUE, language = "english", stemWords = TRUE, stopWords = TRUE, weighting = weightTf) #tm statement
>m
#<<DocumentTermMatrix (documents: 260, terms: 951)>>
Non-/sparse entries: 2669/244591
Sparsity           : 99%
>tdm
#<<TermDocumentMatrix (terms: 1024, documents: 1)>>
Non-/sparse entries: 1024/0
Sparsity           : 0%

如果您需要数据集来更好地理解问题,请告诉我。

【问题讨论】:

    标签: r sparse-matrix tm


    【解决方案1】:

    ?termFreq - 它必须是stemming=TRUE, stopwords=TRUE 而不是stemWords = TRUE, stopWords = TRUE。另请注意,SimpleCorpus 对象会触发 TermDocumentMatrix 的默认行为,这可能会覆盖您的控制参数。

    【讨论】:

    • 所以你建议使用VCorpus?
    • @HimabinduBoddupalli 是的。
    • doc = VCorpus(VectorSource(data)) tdm
    • @HimabinduBoddupalli 你看我的回答了吗?没有控制参数stopWords
    • @HimabinduBoddupalli 然后请编辑您的原始帖子并使其成为一个最小的可重复示例,包括data,以展示两者给出不同的结果。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-07
    • 1970-01-01
    • 1970-01-01
    • 2020-08-30
    • 1970-01-01
    • 2019-06-04
    • 1970-01-01
    相关资源
    最近更新 更多