从这个过程中得到一个dfm:
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)如何将其用于结构建模,如下所示:
library(stm)
fittedModel <- stm(documents = out$documents, vocab = out$vocab, K = 3, init.type = "Spectral")发布于 2020-03-04 19:07:57
您需要使用函数quanteda::convert。此函数可以将dfm转换为不同包的不同格式。有关所有选项,请参见?convert。
请参阅下面的示例以获取示例的解决方案。
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.https://stackoverflow.com/questions/60524551
复制相似问题