R 结构模型的dfm方法

R 结构模型的dfm方法,r,quanteda,R,Quanteda,从该流程获得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) 库(quanteda)

从该流程获得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)
库(quanteda)

df您需要使用函数
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.
库(quanteda)

df您需要使用函数
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.
库(quanteda)
df