Quickly examine the basic polarity
When starting a sentiment project, sometimes a quick polarity()
will help you set expectations or learn about the problem. In this exercise (to save time), you will apply polarity()
to a portion of the comments
vector while the larger polarity object is loaded in the background.
Using a kernel density plot you should notice the reviews do not center on 0. Often there are two causes for this sentiment "grade inflation." First, social norms may lead respondents to be pleasant instead of neutral. This, of course, is channel specific. Particularly snarky channels like e-sports or social media posts may skew negative leading to "deflation." These channels have different expectations. A second possible reason could be "feature based sentiment". In some reviews an author may write "the bed was comfortable and nice but the kitchen was dirty and gross." The sentiment of this type of review encompasses multiple features simultaneously and therefore could make an average score skewed.
In a subsequent exercise you will adjust this "grade inflation" but here explore the reviews without any change.
This exercise is part of the course
Sentiment Analysis in R
Exercise instructions
- Create
practice_pol
usingpolarity()
on the first six reviews as inbos_reviews$comments[1:6]
- Review the returned polarity object by calling
practice_pol
. - Call
summary()
onpractice_pol$all$polarity
- this will access the overall polarity for all 6 comments. - We've also loaded a larger polarity object for all 1000 comments. This new object is called
bos_pol
. Now applysummary()
to the correct list element that returns all polarity scores ofbos_pol
. - The sample code has a barplot and kernel density plot almost ready to print. You must enter the data frame representing all scores. Hint: in the previous step,
polarity
represents a column of this data frame.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Practice apply polarity to first 6 reviews
practice_pol <- ___
# Review the object
___
# Check out the practice polarity
___
# Summary for all reviews
___
# Plot Boston polarity all element
ggplot(___, aes(x = polarity, y = ..density..)) +
geom_histogram(binwidth = 0.25, fill = "#bada55", colour = "grey60") +
geom_density(size = 0.75) +
theme_gdocs()