
6.4
まとめ
■
127
mutate(word = str_replace(word, "'", "")) %>%
group_by(document) %>%
summarize(text = paste(word, collapse = " "))
#
空の「ストップワードファイル」を作成
file.create(empty_file <- tempfile())
docs <- mallet.import(collapsed$document, collapsed$text, empty_file)
mallet_model <- MalletLDA(num.topics = 4)
mallet_model$loadDocuments(docs)
mallet_model$train(100)
しかし、モデルができてしまえば、この章で説明している
tidy()
と
augment()
を
ほぼ同じよ
うに使うことができます。単語が各トピックに属する確率や文書が扱っ
ているトピックの確率なども計算できます。
#
単語
-
トピックのペア
tidy(mallet_model)
#
文書
-
トピックのペア
tidy(mallet_model, matrix = "gamma")
#
「
augment
」のために列名を「
term
」に変更
term_counts <- rename(word_counts, term = word)
augment(mallet_model, term_counts)
ggplot2
を使え ...