Text Mining with R: A Tidy Approach by Julia Silge & David Robinson

Text Mining with R: A Tidy Approach by Julia Silge & David Robinson

Author:Julia Silge & David Robinson [Silge, Julia]
Language: eng
Format: azw3
Publisher: O'Reilly Media
Published: 2017-06-12T04:00:00+00:00


library(tidytext) ap_topics <- tidy(ap_lda, matrix = "beta") ap_topics

## # A tibble: 20,946 × 3 ## topic term beta ## <int> <chr> <dbl> ## 1 1 aaron 1.686917e-12 ## 2 2 aaron 3.895941e-05 ## 3 1 abandon 2.654910e-05 ## 4 2 abandon 3.990786e-05 ## 5 1 abandoned 1.390663e-04 ## 6 2 abandoned 5.876946e-05 ## 7 1 abandoning 2.454843e-33 ## 8 2 abandoning 2.337565e-05 ## 9 1 abbott 2.130484e-06 ## 10 2 abbott 2.968045e-05 ## # ... with 20,936 more rows

Notice that this has turned the model into a one-topic-per-term-per-row format. For each combination, the model computes the probability of that term being generated from that topic. For example, the term “aaron” has a 1.686917 × 10-12 probability of being generated from topic 1, but a 3.8959408 × 10-5 probability of being generated from topic 2.

We could use dplyr’s top_n() to find the 10 terms that are most common within each topic. As a tidy data frame, this lends itself well to a ggplot2 visualization (Figure 6-2).



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.