Chapter 73 TF- IDF of Unigrams (One Word )
We examine the TF-IDF of single words in the following bar graph.This shows the Top Twenty most Important words.
FoodInspectionWords_TF_IDF <- FoodInspectionWords %>%
bind_tf_idf(word, Results, n)
#Choose words with low IDF
LowIDF = FoodInspectionWords_TF_IDF %>%
arrange((idf)) %>%
select(word,idf)
#Get the Unique Words with LowIDF
UniqueLowIDF = unique(LowIDF$word)
plot_FoodInspectionWords_TF_IDF <- FoodInspectionWords_TF_IDF %>%
arrange(desc(tf_idf)) %>%
mutate(word = factor(word, levels = rev(unique(word))))
plot_FoodInspectionWords_TF_IDF %>%
top_n(20) %>%
ggplot(aes(word, tf_idf, fill = Results)) +
geom_col() +
labs(x = NULL, y = "tf-idf") +
coord_flip() +
theme_bw()