我有一个从2个文本文档创建的语料库和一个DocumentTermMatrix,我想要找到单词之间的相关性。无论我选择什么单词,findAssocs
函数都会为语料库中的所有单词返回correlations =1。为什么会这样呢?
以下是我的代码的摘录:
library(tm)
library(SnowballC)
doc <- Corpus(DirSource("C:/Users/biat/Documents/customersatis"))
toSpace <- content_transformer(function(x,pattern) {return (gsub(pattern, " ", x))})
doc <- tm_map(doc, toSpace, "-")
doc <- tm_map(doc, toSpace, ":")
doc <- tm_map(doc, removePunctuation)
doc <- tm_map(doc,content_transformer(tolower))
doc <- tm_map(doc,removeNumbers)
doc <- tm_map(doc,removeWords,stopwords("swedish"))
doc <- tm_map(doc,stripWhitespace)
doc <- tm_map(doc, PlainTextDocument)
doc <- tm_map(doc, stemDocument, "swedish")
dtm <- DocumentTermMatrix(doc)
findAssocs(dtm,"active",0.1)
当我运行它时,结果表明术语"active“与所有560个其他单词的相关性为1,如下所示,但实际上并非如此。
$active
admin actions all analysis arrends
1 1 1 1 1 .........
...................................................
............................ website workshops
1 1
发布于 2018-05-01 17:25:29
正如scoa所说的,你可能有两个文档,其中一个术语同时出现:产生两个。
在将文档转换为语料库之前,请尝试折叠文档:
text <- paste(unlist(text), collapse ="")
https://stackoverflow.com/questions/39292155
复制相似问题