楼主: morningxm
6898 6

[问答] 文本挖掘中lda模型的数据读入问题 [推广有奖]

  • 1关注
  • 1粉丝

初中生

76%

还不是VIP/贵宾

-

威望
0
论坛币
2923 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
71 点
帖子
10
精华
0
在线时间
21 小时
注册时间
2014-2-13
最后登录
2014-11-13

楼主
morningxm 发表于 2014-3-11 09:37:46 |AI写论文
20论坛币
R中的lda包自带的demo运行没有一点问题,但是把demo中的数据换成自己的数据就会在result这句代码处报错,下面是demo代码,自己的数据代码。报错的意思是说我的数据有问题,请哪位大神给小弟解决一下。x<-c(1:1000)y<-c(1,2)
z<-rbind(x,y)
z<-as.matrix(z)
w<-readLines("C:\\Users\\gc\\Desktop\\xl.txt")topicmode
w<-as.vector(w)##是一个特征词向量


##demo
require("lda")
require("ggplot2")
require("reshape2")
data(cora.documents)
data(cora.vocab)

theme_set(theme_bw())  
set.seed(8675309)

K <- 10 ## Num clusters
result <- lda.collapsed.gibbs.sampler(cora.documents,
                                      K,  ## Num clusters
                                      cora.vocab,
                                      25,  ## Num iterations
                                      0.1,
                                      0.1,
                                      compute.log.likelihood=TRUE)

## Get the top words in the cluster
top.words <- top.topic.words(result$topics, 5, by.score=TRUE)

## Number of documents to display
N <- 10

topic.proportions <- t(result$document_sums) / colSums(result$document_sums)
topic.proportions <-
  topic.proportions[sample(1:dim(topic.proportions)[1], N),]
topic.proportions[is.na(topic.proportions)] <-  1 / K

colnames(topic.proportions) <- apply(top.words, 2, paste, collapse=" ")

topic.proportions.df <- melt(cbind(data.frame(topic.proportions),
                                   document=factor(1:N)),
                             variable.name="topic",
                             id.vars = "document")  

qplot(topic, value, fill=document, ylab="proportion",
      data=topic.proportions.df, geom="bar") +
  theme(axis.text.x = element_text(angle=90, hjust=1)) +  
  coord_flip() +
  facet_wrap(~ document, ncol=5)




最佳答案

关键词:文本挖掘 数据读入 LDA Result RESUL 模型

沙发
lww1993 发表于 2014-3-11 09:37:47
x<-c(1:1000)
y<-c(1,2)
z<-rbind(x,y)
z<-list(z=z)

藤椅
lww1993 发表于 2014-3-12 19:10:41
cora.documents是一个list,你的数据中没有list.
cora.documents中的每一个元素是一个2*n矩阵。
你要把你的z<-list(z)才行

板凳
morningxm 发表于 2014-3-14 16:45:53
lww1993 发表于 2014-3-12 19:10
cora.documents是一个list,你的数据中没有list.
cora.documents中的每一个元素是一个2*n矩阵。
你要把你的 ...
cora.documents中的每一个元素是一个2*n矩阵,怎样才能生成这个样的数据格式

报纸
lww1993 发表于 2014-3-14 19:32:38
cora.documents中的每一个元素是代表的意义是每个关键词在当篇文章中出现的频率。

地板
morningxm 发表于 2014-3-14 20:34:43
lww1993 发表于 2014-3-14 19:32
cora.documents中的每一个元素是代表的意义是每个关键词在当篇文章中出现的频率。
谢谢,基本明白了

7
lww1993 发表于 2014-3-16 20:17:46
x<-c(1:1000)
y<-c(1,2)
x<-as.integer(x)
y<-as.integer(y)
z<-rbind(x,y)
z<-list(z)
此时用z代替cora.documents是允许的。

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-30 23:39