【问题标题】:word association - findAssocs and numeric (0)单词关联 - findAssocs 和 numeric (0)
【发布时间】:2017-05-04 15:15:49
【问题描述】:

我刚刚开始掌握 R 中的 tm 包。

可能是一个简单的问题,但尝试使用findAssocs 函数来了解我的客户查询洞察文档中的单词关联,我似乎无法让findAssocs 正常工作。

当我使用以下内容时:

findAssocs(dtm, words, corlimit = 0.30)
 $population
  numeric(0)

 $migration
 numeric(0)

这是什么意思? Words是一个667字的字符向量——肯定有一些相关关系吧?

【问题讨论】:

  • 看起来words 只包含单词populationmigration。或者你的dtm 可能只包含这两个词..

标签: r text-mining tm


【解决方案1】:

考虑以下示例:

library(tm)
corp <- VCorpus(VectorSource(
          c("hello world", "hello another World ", "and hello yet another world")))
tdm <- TermDocumentMatrix(corp)
inspect(tdm)
#          Docs
# Terms     1 2 3
#   and     0 0 1
#   another 0 1 1
#   hello   1 1 1
#   world   1 1 1
#   yet     0 0 1

现在考虑

findAssocs(x=tdm, terms=c("hello", "yet"), corlimit=.4)
# $hello
# numeric(0)
# 
# $yet
#     and another 
#     1.0     0.5 

据我了解,findAssocs 着眼于hello 与除helloyet 之外的所有内容的相关性,以及yet 与除helloyet 之外的所有内容的相关性。 yetand的相关系数为1.0,高于0.4的下限。 yet 也在所有包含another 的文档中的 50% - 这也高于我们的 0.4 限制。

这是另一个展示这一点的示例:

findAssocs(x=tdm, terms=c("yet", "another"), corlimit=0)
# $yet
# and 
#   1 
# 
# $another
# and 
# 0.5 

请注意,hello(和world)不会产生任何结果,因为它们存在于每个文档中。这意味着术语频率的方差为零,cor 在后台产生NA(如cor(rep(1,3), 1:3),它给出NA 加上零标准偏差警告)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多