単語の影響度と頻度分析
データを探索する最も手軽な方法のひとつが頻度分析です。難しくはありませんが、感情分析ではこのシンプルな手法が驚くほど示唆的なことがあります。ここでは棒グラフを作成します。この演習では、可視化を作るために再び moby と bing を使います。
棒の順序を小さいものから大きいものへ並べるには、factor を使った小技を使います。reorder() は、別のスコア変数に基づいて factor の水準順を変更できます。今回は、スコア変数 polarity によって factor 変数 term の順序を並べ替えます。
この演習はコースの一部です
Rで学ぶSentiment Analysis
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
moby_tidy_sentiment <- moby %>%
# Inner join to bing lexicon by term = word
inner_join(bing, by = c("term" = "word")) %>%
# Count by term and sentiment, weighted by count
count(___, ___, wt = ___) %>%
# Pivot sentiment, using n as values
pivot_wider(names_from = ___, values_from = ___, values_fill = ___) %>%
# Mutate to add a polarity column
mutate(polarity = ___ - ___)
# Review
moby_tidy_sentiment