我正在使用'topicmodels'包在R中构建一些主题模型。在预处理和创建文档术语矩阵之后,我将应用以下LDA Gibbs模型。这可能是一个简单的答案,但我是R的新手,所以在这里。有没有办法可以将主题和术语列表及其概率导出到文本文件或Excel文件中?我可以在R中打印它们(如下所示),但不知道如何导出:(
这主要是因为我可以做一些可视化,我确信可以在Excel中完成,但就像我提到的我是新手并且没有太多可用于学习R中的可视化技术。希望这个有道理
k = 33
burnin = 1000
iter = 1000
keep = 50
seed = 2003
model_lda <- LDA(myDtm, k = k, method = "Gibbs",control = list(seed = seed, burnin = burnin, iter = iter, keep = keep))
print(model_lda)
save(model_lda, file = "LDA_Output.RData")
topics(model_lda, 5)
terms(model_lda, 15)
Topic 1 Topic 2 Topic 3 Topic 4 Topic 5 Topic 6 Topic 7
[1,] "seat" "dialogu" "websit" "census" "northern" "growth" "hse"
[2,] "resum" "church" "partnership" "disabl" "univers" "adjust" "legisl"
[3,] "suspend" "congreg" "nesc" "cso" "peac" "forecast" "die"
[4,] "adjourn" "school" "site" "statist" "unemploy" "bernard" "legal"
[5,] "fisheri" "survivor" "nesf" "survey" "polic" "burton" "child"
答案 0 :(得分:0)
首先,您可以使用permuteRanges
读取数据,然后可以使用readr
R包。例如:
tidytext
上述代码应分别在readr::write_csv(tidy(model_lda, "beta"), "beta.csv")
readr::write_csv(tidy(model_lda, "gamma"), "gamma.csv")
和beta
中保存gamma
矩阵和beta.csv
矩阵。
您还可以在此处找到对我有用的章节:http://tidytextmining.com/topicmodeling.html