开始使用免费开始使用

快速体验文本挖掘

有时,只需查看最常见的词,就能推测作者的意图和要点。

Bag-of-words 文本挖掘的核心是统计一组文档中的术语或 n-gram 的出现次数。请看下面的句子,我们已将其保存到 text 中,并放入了您的工作区:

text <- "Text mining usually involves the process of structuring the input text. The overarching goal is, essentially, to turn text into data for analysis, via the application of natural language processing (NLP) and analytical methods."

手动统计上面句子中的单词很麻烦!幸运的是,qdap 包提供了更好的方法。您可以调用 freq_terms 函数并指定 4,轻松找出 text 中出现频率最高的 4 个术语(包含并列并列的情况)。

frequent_terms <- freq_terms(text, 4)

frequent_terms 对象存储了所有不重复的单词及其计数。然后,您可以对 frequent_terms 对象调用 plot 函数,直接绘制条形图。

plot(frequent_terms)

本练习是课程的一部分

使用 R 的 Bag-of-Words 进行文本挖掘

查看课程

练习说明

我们在您的工作区中创建了一个名为 new_text 的对象,其中包含若干句子。

  • 加载 qdap 包。
  • new_text 打印到控制台。
  • 创建 term_count,其中包含 new_text 中出现频率最高的 10 个术语。
  • 使用 term_count 的结果绘制条形图。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Load qdap
___

# Print new_text to the console
new_text

# Find the 10 most frequent terms: term_count
term_count <- ___

# Plot term_count
___
编辑并运行代码