开始使用免费开始使用

多文本列

在本练习中,您将继续使用航空公司的 Twitter 数据。数据集 tweets 已为您导入。

在某些情况下,一个数据集中可能有不止一个文本列,您可能希望为每个文本列都创建数值表示。在这里,除了包含推文正文的 text 列之外,还有第二个文本列 negativereason,其中包含顾客给出负面评价的原因。

您的任务是为这两列都构建 BOW 表示,并指定所需的停用词。

本练习是课程的一部分

Python 中的情感分析

查看课程

练习说明

  • 导入向量化工具包和默认的英文停用词列表。
  • 更新默认的英文停用词列表,创建 my_stop_words 集合。
  • 在第一个向量化器中将停用词参数设置为更新后的集合,在第二个向量化器中将其设置为默认的英文停用词集合。

交互式实操练习

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

# Import the vectorizer and default English stop words list
____

# Define the stop words
my_stop_words = ____._____(['airline', 'airlines', '@', 'am', 'pm'])
 
# Build and fit the vectorizers
vect1 = CountVectorizer(____=my_stop_words)
vect2 = CountVectorizer(____=____) 
vect1.fit(tweets.text)
vect2.fit(tweets.negative_reason)

# Print the last 15 features from the first, and all from second vectorizer
print(vect1.get_feature_names()[-15:])
print(vect2.get_feature_names())
编辑并运行代码