请原谅我,因为我对此非常陌生,我正在为证书课程的一个项目工作。
我有.csv数据集,我是通过从Pubmed和Embase数据库中检索书目记录获得的。有1034行。有几个列,但是,我尝试从一个列创建主题模型,抽象列和一些记录没有抽象。我做了一些处理(移除断句、标点符号等)并且能够对发生超过200次的单词进行限制,并按等级创建一个频繁的术语列表,并且还可以与选定的单词进行单词关联。因此,似乎r在抽象字段中看到了单词本身。当我尝试使用topicmodels包创建主题模型时,我的问题就来了。这是我正在使用的代码。
#including 1st 3 lines for reference
options(header = FALSE, stringsAsFactors = FALSE, FileEncoding =
"latin1")
records <- read.csv("Combined.csv")
AbstractCorpus <- Corpus(VectorSource(records$Abstract))
AbstractTDM <- TermDocumentMatrix(AbstractCorpus)
library(topicmodels)
library(lda)
lda <- LDA(AbstractTDM, k = 8)
(term <- terms(lda, 6))
term <- (apply(term, MARGIN = 2, paste, collapse = ","))但是,我得到的主题输出如下。
Topic 1 Topic 2 Topic 3 Topic 4 Topic 5 Topic 6 Topic 7 Topic 8
[1,] "499" "733" "390" "833" "17" "413" "719" "392"
[2,] "484" "655" "808" "412" "550" "881" "721" "61"
[3,] "857" "299" "878" "909" "15" "258" "47" "164"
[4,] "491" "672" "313" "1028" "126" "55" "375" "987"
[5,] "734" "430" "405" "102" "13" "193" "83" "588"
[6,] "403" "52" "489" "10" "598" "52" "933" "980" 为什么我在这里看不到单词而不是数字?
此外,下面的代码基本上是从主题模型的r PDF中提取的,它确实为我产生了值,但主题仍然是数字而不是文字,这对我来说是毫无意义的。
#using information from topicmodels paper
library(tm)
library(topicmodels)
library(lda)
AbstractTM <- list(VEM = LDA(AbstractTDM, k = 10, control = list(seed =
505)), VEM_fixed = LDA(AbstractTDM, k = 10, control = list(estimate.alpha
= FALSE, seed = 505)), Gibbs = LDA(AbstractTDM, k = 10, method = "Gibbs",
Control = list(seed = 505, burnin = 100, thin = 10, iter = 100)), CTM =
CTM(AbstractTDM, k = 10, control = list(seed = 505, var = list(tol =
10^-4), em = list(tol = 10^-3))))
#To compare the fitted models we first investigate the α values of the
models fitted with VEM and α estimated and with VEM and α fixed
sapply(AbstractTM[1:2], slot, "alpha")
#Find entropy
sapply(AbstractTM, function(x)mean(apply(posterior(x)$topics, 1,
function(z) - sum(z * log(z)))))
#Find estimated topics and terms
Topic <- topics(AbstractTM[["VEM"]], 1)
Topic
#find 5 most frequent terms for each topic
Terms <- terms(AbstractTM[["VEM"]], 5)
Terms[,1:5]对这个问题有什么想法吗?
发布于 2017-04-17 04:55:28
阅读topicmodels文档后,LDA()函数似乎需要一个DocumentTermMatrix,而不是TermDocumentMatrix。尝试用DocumentTermMatrix(AbstractCorpus)创建前者,看看它是否有效。
https://stackoverflow.com/questions/43444289
复制相似问题