【问题标题】:Topic Modelling in RR中的主题建模
【发布时间】:2017-10-07 18:16:54
【问题描述】:

我正在根据公共评论数据创建一个相关主题模型,并得到一个相当奇怪的错误。

当我在 CTM 上调用 terms(ctm1, 5) 时,我会返回文档的名称,而不是每个主题的前 5 个术语。

我跑的更详细,

library(topicmodels)
library(data.table)
library(tm)

a  <-Corpus(DirSource("~/text", encoding="UTF-8"), readerControl = 
list(language="lat")) 
a <- tm_map(a, removeNumbers)
a <- tm_map(a, removePunctuation)
a <- tm_map(a , stripWhitespace)
a <- tm_map(a, tolower)
a <- tm_map(a, removeWords, stopwords("english")) 
a <- tm_map(a, stemDocument, language = "english")
adtm <-TermDocumentMatrix(a) 
adtm <- removeSparseTerms(adtm, 0.75)

ctm1 <- CTM(adtm, 30, method = "VEM", control = NULL, model = NULL)
terms(ctm1, 5)

返回的

terms(ctm1)
          Topic 1  "cmnt656661.txt" 

(等等)

【问题讨论】:

    标签: r tm topic-modeling


    【解决方案1】:

    我们无法确定,因为您没有提供数据;但很可能您没有正确导入文件。见?DirSource(我的重点):

    目录完整路径名的字符向量;默认 对应工作目录getwd()。

    在您的情况下,您似乎应该这样做:

    a <- Corpus(DirSource(list.files("~/text", full.names = TRUE)))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-16
      • 2018-02-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多