CommencerCommencer gratuitement

Word impact, frequency analysis

One of the easiest ways to explore data is with a frequency analysis. Although not difficult, in sentiment analysis this simple method can be surprisingly illuminating. Specifically, you will build a barplot. In this exercise you are once again working with moby and bing to construct your visual.

To get the bars ordered from lowest to highest, you will use a trick with factors. reorder() lets you change the order of factor levels based upon another scoring variable. In this case, you will reorder the factor variable term by the scoring variable polarity.

Cet exercice fait partie du cours

Sentiment Analysis in R

Afficher le cours

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

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
Modifier et exécuter le code