| 所在主题: | |
| 文件名: body1.txt | |
| 资料下载链接地址: https://bbs.pinggu.org/a-1787381.html | |
| 附件大小: | |
|
原本数据只有1764条,我想对数据做层次聚类,再用cutree显示分类,可是显示分类时竟然有3549个数据。新手啊,为了做毕设才学的,好着急,以下是代码和数据在附件里,望各路大神帮帮小女子啊!!
csv <- read.table("body1.txt",header=T) csv<-t(csv) mystopwords<-unlist (read.table("StopWords.txt",stringsAsFactors=F)) library(tm) #移除数字 removeNumbers = function(x) { ret = gsub("[0-90123456789]","",x) } #中文分词,也可以考虑使用rmmseg4j、rsmartcn wordsegment<- function(x) { library(Rwordseg) segmentCN(x) } #去除停止词,效果比较差,可以进一步完善 removeStopWords = function(x,words) { ret = character(0) index <- 1 it_max <- length(x) while (index <= it_max) { if (length(words[words==x[index]]) <1) ret <- c(ret,x[index]) index <- index +1 } ret } Sys.setenv(JAVA_HOME='C:/ProgramFiles/Java/jdk1.6.0_43/jre') sample.words <- lapply(csv, removeNumbers) sample.words <- lapply(sample.words, wordsegment) #先处理中文分词,再处理stopwords,防止全局替换丢失信息 sample.words <- lapply(sample.words, removeStopWords, mystopwords) #构建语料库 corpus = Corpus(VectorSource(sample.words))
sample.dtm<- DocumentTermMatrix(corpus, control = list(wordLengths = c(2, Inf))) dtm2 = removeSparseTerms(sample.dtm,sparse=0.99) d <- dist(dtm2, method ="euclidean") fit <- hclust(d,method="ward.D") plot(fit) cutree(fit,k=8)#聚类的图显示的是8类,但数据太多特别密集,也看不出有多少数据,不知道是1700条还是3500条 |
|
熟悉论坛请点击新手指南
|
|
| 下载说明 | |
|
1、论坛支持迅雷和网际快车等p2p多线程软件下载,请在上面选择下载通道单击右健下载即可。 2、论坛会定期自动批量更新下载地址,所以请不要浪费时间盗链论坛资源,盗链地址会很快失效。 3、本站为非盈利性质的学术交流网站,鼓励和保护原创作品,拒绝未经版权人许可的上传行为。本站如接到版权人发出的合格侵权通知,将积极的采取必要措施;同时,本站也将在技术手段和能力范围内,履行版权保护的注意义务。 (如有侵权,欢迎举报) |
|
京ICP备16021002号-2 京B2-20170662号
京公网安备 11010802022788号
论坛法律顾问:王进律师
知识产权保护声明
免责及隐私声明