| 所在主题: | |
| 文件名: body1.txt | |
| 资料下载链接地址: https://bbs.pinggu.org/a-1788343.html | |
| 附件大小: | |
|
想做个层次聚类,转置后设置行名时提示Error in `rownames<-`(`*tmp*`, value = c(271L, 247L, 342L, 1158L, 1338L,:
length of 'dimnames' [1] not equal to array extent plot的时候又提示 Error in graphics:::plotHclust(n1, merge, height, order(x$order), hang,: 谱系图输入不对 以下是代码和数据,望各位大神帮忙看看,在下新手,多谢多谢! > csv <- read.table("body1.txt",header=T) > 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:/Program Files/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))) > sample_matrix =as.matrix(sample.dtm) > rownames(sample_matrix)<- csv$newsid Error in `rownames<-`(`*tmp*`, value = c(271L, 247L, 342L, 1158L, 1338L,: length of 'dimnames' [1] not equal to array extent > > dtm2 = removeSparseTerms(sample.dtm, sparse=0.99) > d <- dist(dtm2, method = "euclidean") > fit <- hclust(d, method="ward.D") > plot(fit) Error in graphics:::plotHclust(n1, merge, height, order(x$order), hang,: 谱系图输入不对 还想问问大家,由于我的数据量比较大,做层次聚类的谱系图会太密集,看不清,有什么更好的文本聚类方法吗?我后续还想进行如用cutree提取出每条新闻属于哪一类的操作,不知道有没有别的方法或函数能做到的,多谢大家了! |
|
熟悉论坛请点击新手指南
|
|
| 下载说明 | |
|
1、论坛支持迅雷和网际快车等p2p多线程软件下载,请在上面选择下载通道单击右健下载即可。 2、论坛会定期自动批量更新下载地址,所以请不要浪费时间盗链论坛资源,盗链地址会很快失效。 3、本站为非盈利性质的学术交流网站,鼓励和保护原创作品,拒绝未经版权人许可的上传行为。本站如接到版权人发出的合格侵权通知,将积极的采取必要措施;同时,本站也将在技术手段和能力范围内,履行版权保护的注意义务。 (如有侵权,欢迎举报) |
|
京ICP备16021002号-2 京B2-20170662号
京公网安备 11010802022788号
论坛法律顾问:王进律师
知识产权保护声明
免责及隐私声明