Comparison Cloud
This exercise will create a common visual for you to understand term frequency. Specifically, you will review the most frequent terms from among the positive and negative collapsed documents. Recall the TermDocumentMatrix all_tdm
you created earlier. Instead of 1000 rental reviews the matrix contains 2 documents containing all reviews separated by the polarity()
score.
It's usually easier to change the TDM to a matrix. From there you simply rename the columns. Remember that the colnames()
function is called on the left side of the assignment operator as shown below.
colnames(OBJECT) <- c("COLUMN_NAME1", "COLUMN_NAME2")
Once done, you will reorder the matrix to see the most positive and negative words. Review these terms so you can answer the conclusion exercises!
Lastly, you'll visualize the terms using comparison.cloud()
.
This exercise is part of the course
Sentiment Analysis in R
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Matrix
___
# Column names
colnames(___) <- ___
# Top pos words
order_by_pos <- order(all_tdm_m[, ___], decreasing = ___)
# Review top 10 pos words
all_tdm_m[order_by_pos, ] %>% head(___)
# Top neg words
order_by_neg <- order(___, decreasing = ___)
# Review top 10 neg words
all_tdm_m[___, ] %>% ___