我是从以下https://rstudio-pubs-static.s3.amazonaws.com/31867_8236987cf0a8444e962ccd2aec46d9c3.htmlR型聚类分析
library(cluster)
d <- dist(t(dtmss), method="euclidian")
fit <- hclust(d=d, method="ward")
fit
plot.new()
plot(fit, hang=-1)
groups <- cutree(fit, k=5)
rect.hclust(fit, k=5, border="red")
如何打印每个集群中的单词下面列出的代码?树状图变得非常拥挤并且完全不可读。
谢谢!
EDITS:
对于输入,考虑一个名为 “注释” 列任何CSV文件。每个观察(50行)都有文字注释。
library(tm)
input = read.csv("FILEPATH/InputFile.csv")
summary(input)
comments <- Corpus(VectorSource(input$Comment))
data <- tm_map(comments, removePunctuation)
data <- tm_map(data, removeNumbers)
data <- tm_map(data, tolower)
data <- tm_map(data, removeWords, stopwords("english"))
data <- tm_map(data, PlainTextDocument)
dtm <- DocumentTermMatrix(data)
freq <- colSums(as.matrix(dtm))
ord <- order(freq)
findFreqTerms(dtm, lowfreq = 10)
freq <- sort(colSums(as.matrix(dtm)), decreasing = TRUE)
head(freq, 30)
dtms <- removeSparseTerms(dtm, 0.1)
inspect(dtms)
library(cluster)
d <- dist(t(dtms), method="euclidian")
fit <- hclust(d=d, method="ward")
fit
plot(fit, hang=-1)
plot.new()
plot(fit, hang=-1)
groups <- cutree(fit, k=5)
rect.hclust(fit, k=5, border="red")
我希望这是足够的信息:
然后我从上面的链接中使用的代码。
再次感谢。
的例子,当你”已经在这里介绍过,不可重现。我认为在你的教程中需要包含更多的代码和数据才能满足MCVE要求。 http://stackoverflow.com/help/mcve –
我试图重现它与虹膜数据集... –
@ stata00编辑帮助了很多。它只是缺少实际的输入文件,我想。是否有指向该教程的.csv的链接,您可以包含该链接? –