首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对结构模型使用dfm

对结构模型使用dfm
EN

Stack Overflow用户
提问于 2020-03-04 19:00:45
回答 1查看 47关注 0票数 0

从这个过程中得到一个dfm:

代码语言:javascript
复制
library(quanteda)
df <- data.frame(text = c("one text here", "one more here and there"))
toks_tweets <- tokens(df$text, remove_punct = TRUE)
dfmat_tweets <- dfm(toks_tweets,
    stem = FALSE,
    remove_punct = TRUE)

如何将其用于结构建模,如下所示:

代码语言:javascript
复制
library(stm)
fittedModel <- stm(documents = out$documents, vocab = out$vocab, K = 3, init.type = "Spectral")
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-04 19:07:57

您需要使用函数quanteda::convert。此函数可以将dfm转换为不同包的不同格式。有关所有选项,请参见?convert

请参阅下面的示例以获取示例的解决方案。

代码语言:javascript
复制
library(quanteda)
df <- data.frame(text = c("one text here", "one more here and there"), stringsAsFactors = FALSE)
toks_tweets <- tokens(df$text, remove_punct = TRUE)
dfmat_tweets <- dfm(toks_tweets,
                    stem = FALSE,
                    remove_punct = TRUE)

out <- convert(dfmat_tweets, to = "stm")  # convert to stm format

library(stm)
fittedModel <- stm(documents = out$documents, vocab = out$vocab, K = 3, init.type = "Spectral")

fittedModel
# A topic model with 3 topics, 2 documents and a 6 word dictionary.
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60524551

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档