เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

TFIDF Practice

Earlier you looked at a bag-of-words representation of articles on crude oil. Calculating TFIDF values relies on this bag-of-words representation, but takes into account how often a word appears in an article, and how often that word appears in the collection of articles.

To determine how meaningful words would be when comparing different articles, calculate the TFIDF weights for the words in crude, a collection of 20 articles about crude oil.

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Introduction to Natural Language Processing in R

ดูคอร์ส

คำแนะนำการฝึกหัด

  • Calculate TFIDF values for crude by article_id and by word. Save the resulting tibble as crude_weights.
  • Sort crude_weights with the arrange() function by descending tf_idf values.
  • Filter crude_weights to the lowest non-zero tf_idf values. Again, use the arrange function.

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# Create a tibble with TFIDF values
___ <- crude_tibble %>%
  unnest_tokens(output = "word", token = "words", input = text) %>%
  anti_join(stop_words) %>%
  count(article_id, word) %>%
  ___(___, ___, n)

# Find the highest TFIDF values
crude_weights %>%
  ___(desc(___))

# Find the lowest non-zero TFIDF values
crude_weights %>%
  filter(___ != ___) %>%
  ___(___)
แก้ไขและรันโค้ด