Aan de slagGa gratis aan de slag

Compare Tidy Sentiment to Qdap Polarity

Here you will learn that differing sentiment methods will cause different results. Often you will simply need to have results align directionally although the specifics may be different. In the last exercise you created tidy_reviews which is a data frame of rental reviews without stopwords. Earlier in the chapter, you calculated and plotted qdap's basic polarity() function. This showed you the reviews tend to be positive.

Now let's perform a similar analysis the tidytext way! Recall from an earlier chapter you will perform an inner_join() followed by count() and then a pivot_wider().

Lastly, you will create a new column using mutate() and passing in positive - negative.

Deze oefening maakt deel uit van de cursus

Sentiment Analysis in R

Cursus bekijken

Oefeninstructies

  • Using the get_sentiments() function with "bing" will obtain the bing subjectivity lexicon. Call the lexicon bing.
  • Since you already wrote this code in Chapter 2 simply enter in the lexicon object, bing, the new column name (polarity) and its calculation within mutate().
  • Lastly call summary() on the new object pos_neg. Although the values are different, after reviewing the mean, are most rental reviews similarly positive compared to using polarity()? Do you see "grade inflation?"

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Get the correct lexicon
bing <- ___

# Calculate polarity for each review
pos_neg <- tidy_reviews %>% 
  inner_join(___) %>%
  count(sentiment) %>%
  pivot_wider(names_from = sentiment, values_from = n, values_fill = 0) %>% 
  mutate(___ = ___ - ___)

# Check outcome
___
Code bewerken en uitvoeren