使用 DocumentTermMatrix() 的更多停用词

Posted

技术标签:

【中文标题】使用 DocumentTermMatrix() 的更多停用词【英文标题】:More stop words using the DocumentTermMatrix() 【发布时间】:2020-11-25 02:09:06 【问题描述】:

目前,我在 R 中使用函数 DocumentTermMatrix() 来拟合 LDA 模型。除了默认的停用词之外,我还想添加我自己应该删除的词。

library(tm)
myStopwords <- c("aa", "bb")
dtm <- DocumentTermMatrix(myCorpus,
                           control = list(
                           tolower = TRUE,
                           removePunctuation = TRUE,
                           removeNumbers= TRUE,
                           stemming = FALSE,
                           stopwords = TRUE,
                           minWordLength = 2))

谁能帮我在上面的代码中添加我自己的停用词?谢谢!

【问题讨论】:

【参考方案1】:

您可以通过在DocumentTermMatrix 函数中添加removeWords = c("aa", "bb") 来添加自己的停用词。

library(tm)
myStopwords <- c("aa", "bb")
dtm <- DocumentTermMatrix(myCorpus,
                           control = list(
                           tolower = TRUE,
                           removePunctuation = TRUE,
                           removeNumbers= TRUE,
                           stemming = FALSE,
                           stopwords = TRUE,
                           removeWords = c("aa","bb"),
                           minWordLength = 2))
))

【讨论】:

以上是关于使用 DocumentTermMatrix() 的更多停用词的主要内容,如果未能解决你的问题,请参考以下文章